Пример #1
0
 public function getServerFilename($which = 'main')
 {
     global $MEDIA_DIRECTORY, $THUMBNAIL_WIDTH;
     if ($this->isExternal() || !$this->file) {
         // External image, or (in the case of corrupt GEDCOM data) no image at all
         return $this->file;
     } elseif ($which == 'main') {
         // Main image
         return WT_DATA_DIR . $MEDIA_DIRECTORY . $this->file;
     } else {
         // Thumbnail
         $file = WT_DATA_DIR . $MEDIA_DIRECTORY . 'thumbs/' . $this->file;
         // Does the thumbnail exist?
         if (file_exists($file)) {
             return $file;
         }
         // Does a user-generated thumbnail exist?
         $user_thumb = preg_replace('/\\.[a-z0-9]{3,5}$/i', '.png', $file);
         if (file_exists($user_thumb)) {
             return $user_thumb;
         }
         // Does the folder exist for this thumbnail?
         if (!is_dir(dirname($file)) && !@mkdir(dirname($file), WT_PERM_EXE, true)) {
             Log::addMediaLog('The folder ' . dirname($file) . ' could not be created for ' . $this->getXref());
             return $file;
         }
         // Is there a corresponding main image?
         $main_file = WT_DATA_DIR . $MEDIA_DIRECTORY . $this->file;
         if (!file_exists($main_file)) {
             Log::addMediaLog('The file ' . $main_file . ' does not exist for ' . $this->getXref());
             return $file;
         }
         // Try to create a thumbnail automatically
         $imgsize = getimagesize($main_file);
         if ($imgsize[0] && $imgsize[1]) {
             // Image small enough to be its own thumbnail?
             if ($imgsize[0] < $THUMBNAIL_WIDTH) {
                 Log::addMediaLog('Thumbnail created for ' . $main_file . ' (copy of main image)');
                 @copy($main_file, $file);
             } else {
                 if (hasMemoryForImage($main_file)) {
                     switch ($imgsize['mime']) {
                         case 'image/png':
                             $main_image = @imagecreatefrompng($main_file);
                             break;
                         case 'image/gif':
                             $main_image = @imagecreatefromgif($main_file);
                             break;
                         case 'image/jpeg':
                             $main_image = @imagecreatefromjpeg($main_file);
                             break;
                         default:
                             return $file;
                             // Nothing else we can do :-(
                     }
                     if ($main_image) {
                         // How big should the thumbnail be?
                         $width = $THUMBNAIL_WIDTH;
                         $height = round($imgsize[1] * ($width / $imgsize[0]));
                         $thumb_image = @imagecreatetruecolor($width, $height);
                         // Create a transparent background, instead of the default black one
                         @imagesavealpha($thumb_image, true);
                         @imagefill($thumb_image, 0, 0, imagecolorallocatealpha($thumb_image, 0, 0, 0, 127));
                         // Shrink the image
                         @imagecopyresampled($thumb_image, $main_image, 0, 0, 0, 0, $width, $height, $imgsize[0], $imgsize[1]);
                         switch ($imgsize['mime']) {
                             case 'image/png':
                                 @imagepng($thumb_image, $file);
                                 break;
                             case 'image/gif':
                                 @imagegif($thumb_image, $file);
                                 break;
                             case 'image/jpeg':
                                 @imagejpeg($thumb_image, $file);
                                 break;
                         }
                         @imagedestroy($main_image);
                         @imagedestroy($thumb_image);
                         Log::addMediaLog('Thumbnail created for ' . $main_file);
                     } else {
                         Log::addMediaLog('Failed to create thumbnail for ' . $main_file);
                     }
                 } else {
                     Log::addMediaLog('Not enough memory to create thumbnail for ' . $main_file);
                 }
             }
         }
         return $file;
     }
 }
Пример #2
0
$type = isImageTypeSupported($imgsize['ext']);
$usewatermark = false;
// if this image supports watermarks and the watermark module is intalled...
if ($type) {
    // if this is not a thumbnail, or WATERMARK_THUMB is true
    if ($which == 'main' || $WATERMARK_THUMB) {
        // if the user’s priv’s justify it...
        if (WT_USER_ACCESS_LEVEL > $SHOW_NO_WATERMARK) {
            // add a watermark
            $usewatermark = true;
        }
    }
}
// determine whether we have enough memory to watermark this image
if ($usewatermark) {
    if (!hasMemoryForImage($serverFilename)) {
        // not enough memory to watermark this file
        $usewatermark = false;
    }
}
$watermarkfile = "";
$generatewatermark = false;
if ($usewatermark) {
    if ($which == 'thumb') {
        $watermarkfile = WT_DATA_DIR . $MEDIA_DIRECTORY . 'watermark/' . WT_GEDCOM . '/thumb/' . $media->getFilename();
    } else {
        $watermarkfile = WT_DATA_DIR . $MEDIA_DIRECTORY . 'watermark/' . WT_GEDCOM . '/' . $media->getFilename();
    }
    if (!file_exists($watermarkfile)) {
        // no saved watermark file exists
        // generate the watermark file