Пример #1
0
 // Set all params for requested size:
 list($thumb_type, $thumb_width, $thumb_height, $thumb_quality, $thumb_percent_blur) = $thumbnail_sizes[$size_name];
 $Filetype =& $File->get_Filetype();
 // pre_dump( $Filetype );
 // TODO: dh> Filetype may be NULL here! see also r1.18 (IIRC)
 $mimetype = $Filetype->mimetype;
 // pre_dump( $mimetype );
 // Try to output the cached thumbnail:
 $err = $File->output_cached_thumb($size_name, $mimetype, $mtime, $size_x);
 //pre_dump( $err );
 if ($err == '!Thumbnail not found in' . $Settings->get('evocache_foldername')) {
     // The thumbnail wasn't already in the cache, try to generate and cache it now:
     $err = NULL;
     // Short error code
     list($src_width, $src_height) = imgsize($File->get_full_path());
     if (!$resample_all_images && check_thumbnail_sizes($thumb_type, $thumb_width, $thumb_height, $src_width, $src_height)) {
         // There is no need to resample, use original!
         $err = $File->get_af_thumb_path($size_name, $mimetype, true, $size_x);
         if ($err[0] != '!' && @copy($File->get_full_path(), $err)) {
             // File was saved. Ouput that same file immediately:
             // note: @copy returns FALSE on failure, if not muted it'll print the error on screen
             $err = $File->output_cached_thumb($size_name, $mimetype, $mtime, $size_x);
         }
     } else {
         // Resample
         list($err, $src_imh) = load_image($File->get_full_path(), $mimetype);
         if (empty($err)) {
             list($err, $dest_imh) = generate_thumb($src_imh, $thumb_type, $thumb_width, $thumb_height, $thumb_percent_blur, $size_x);
             if (empty($err)) {
                 $err = $File->save_thumb_to_cache($dest_imh, $size_name, $mimetype, $thumb_quality, $size_x);
                 if (empty($err)) {
Пример #2
0
/**
 * Generate a thumbnail
 *
 * @param resource Image resource
 * @param string Thumbnail type ('crop'|'crop-top'|'fit')
 * @param int Thumbnail width
 * @param int Thumbnail height
 * @param int Thumbnail percent of blur effect (0 - No blur, 1% - Max blur effect, 99% - Min blur effect)
 * @param integer Ratio size, can be 1, 2 and etc.
 * @return array short error code + dest image handler
 */
function generate_thumb($src_imh, $thumb_type, $thumb_width, $thumb_height, $thumb_percent_blur = 0, $size_x = 1)
{
    $src_width = imagesx($src_imh);
    $src_height = imagesy($src_imh);
    $size_x = intval($size_x);
    if ($size_x > 1) {
        // Use the expanded size
        $thumb_width = $thumb_width * $size_x;
        $thumb_height = $thumb_height * $size_x;
    }
    if (check_thumbnail_sizes($thumb_type, $thumb_width, $thumb_height, $src_width, $src_height)) {
        // There is no need to resample, use original!
        return array(NULL, $src_imh);
    }
    switch ($thumb_type) {
        case 'crop':
        case 'crop-top':
            $align = $thumb_type == 'crop-top' ? 'top' : 'center';
            list($src_x, $src_y, $src_width, $src_height) = crop_to_constraint($src_width, $src_height, $thumb_width, $thumb_height, $align);
            $dest_width = $thumb_width;
            $dest_height = $thumb_height;
            break;
        case 'fit':
        default:
            list($dest_width, $dest_height) = scale_to_constraint($src_width, $src_height, $thumb_width, $thumb_height);
            $src_x = $src_y = 0;
    }
    // pre_dump( $src_x, $src_y, $dest_width, $dest_height, $src_width, $src_height );
    // Create a transparent image:
    $dest_imh = imagecreatetruecolor($dest_width, $dest_height);
    imagealphablending($dest_imh, true);
    imagefill($dest_imh, 0, 0, imagecolortransparent($dest_imh, imagecolorallocatealpha($dest_imh, 0, 0, 0, 127)));
    imagesavealpha($dest_imh, true);
    if (!imagecopyresampled($dest_imh, $src_imh, 0, 0, $src_x, $src_y, $dest_width, $dest_height, $src_width, $src_height)) {
        return array('!GD-library internal error (resample)', $dest_imh);
    }
    if ($thumb_percent_blur > 0) {
        // Apply blur effect
        $dest_imh = pixelblur($dest_imh, $dest_width, $dest_height, $thumb_percent_blur);
    }
    // TODO: imageinterlace();
    return array(NULL, $dest_imh);
}
Пример #3
0
 /**
  * Calculate what sizes are used for thumbnail really
  *
  * @param string Thumbnail size name
  * @return boolean|array FALSE on wrong size name OR Array with keys: 0 - width, 1 - height
  */
 function get_thumb_size($size_name = 'fit-80x80')
 {
     global $thumbnail_sizes;
     if (!isset($thumbnail_sizes[$size_name])) {
         // Wrong thumbnail size name
         return false;
     }
     $thumb_type = $thumbnail_sizes[$size_name][0];
     $thumb_width = $thumbnail_sizes[$size_name][1];
     $thumb_height = $thumbnail_sizes[$size_name][2];
     load_funcs('files/model/_image.funcs.php');
     list($orig_width, $orig_height) = $this->get_image_size('widthheight');
     if (check_thumbnail_sizes($thumb_type, $thumb_width, $thumb_height, $orig_width, $orig_height)) {
         // Use the sizes of the original image
         $width = $orig_width;
         $height = $orig_height;
     } else {
         // Calculate the sizes depending on thumbnail type
         if ($thumb_type == 'fit') {
             list($width, $height) = scale_to_constraint($orig_width, $orig_height, $thumb_width, $thumb_height);
         } else {
             // crop & crop-top
             $width = $thumb_width;
             $height = $thumb_height;
         }
     }
     return array($width, $height);
 }