Exemple #1
0
 /**
  * nggAdmin::set_watermark() - set the watermark for the image
  * 
  * @class nggAdmin
  * @param object | int $image contain all information about the image or the id
  * @return string result code
  */
 function set_watermark($image)
 {
     global $ngg;
     if (!class_exists('ngg_Thumbnail')) {
         require_once nggGallery::graphic_library();
     }
     if (is_numeric($image)) {
         $image = nggdb::find_image($image);
     }
     if (!is_object($image)) {
         return __('Object didn\'t contain correct data', 'nggallery');
     }
     // before we start we import the meta data to database (required for uploads before V1.4.0)
     nggAdmin::maybe_import_meta($image->pid);
     if (!is_writable($image->imagePath)) {
         return ' <strong>' . $image->filename . __(' is not writeable', 'nggallery') . '</strong>';
     }
     $file = new ngg_Thumbnail($image->imagePath, TRUE);
     // skip if file is not there
     if (!$file->error) {
         // If required save a backup copy of the file
         if ($ngg->options['imgBackup'] == 1 && !file_exists($image->imagePath . '_backup')) {
             @copy($image->imagePath, $image->imagePath . '_backup');
         }
         if ($ngg->options['wmType'] == 'image') {
             $file->watermarkImgPath = $ngg->options['wmPath'];
             $file->watermarkImage($ngg->options['wmPos'], $ngg->options['wmXpos'], $ngg->options['wmYpos']);
         }
         if ($ngg->options['wmType'] == 'text') {
             $file->watermarkText = $ngg->options['wmText'];
             $file->watermarkCreateText($ngg->options['wmColor'], $ngg->options['wmFont'], $ngg->options['wmSize'], $ngg->options['wmOpaque']);
             $file->watermarkImage($ngg->options['wmPos'], $ngg->options['wmXpos'], $ngg->options['wmYpos']);
         }
         $file->save($image->imagePath, $ngg->options['imgQuality']);
     }
     $file->destruct();
     if (!empty($file->errmsg)) {
         return ' <strong>' . $image->filename . ' (Error : ' . $file->errmsg . ')</strong>';
     }
     return '1';
 }