Changeset 9756


Ignore:
Timestamp:
03/18/11 15:03:10 (9 years ago)
Author:
patdenice
Message:

Compatibility with imagemagik

Location:
extensions/square_thumbnails/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • extensions/square_thumbnails/trunk/functions.inc.php

    r9754 r9756  
    154154  if (is_imagick()) 
    155155  { 
    156     return pwg_image_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata); 
    157   } 
    158   else 
    159   { 
    160     return pwg_image_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality); 
     156    return upload_square_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata); 
     157  } 
     158  else 
     159  { 
     160    return upload_square_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality); 
    161161  } 
    162162} 
    163163 
    164 function upload_square_resize_gd($result, $source_filepath, $destination_filepath, $max_width, $max_height, $quality) 
     164function upload_square_resize_gd($source_filepath, $destination_filepath, $max_width, $max_height, $quality) 
    165165{ 
    166166  if (!function_exists('gd_info')) 
     
    175175  if (in_array($extension, array('jpg', 'jpeg'))) 
    176176  { 
    177     $source_image = imagecreatefromjpeg($source_filepath); 
     177    $source_image = @imagecreatefromjpeg($source_filepath); 
    178178  } 
    179179  else if ($extension == 'png') 
    180180  { 
    181     $source_image = imagecreatefrompng($source_filepath); 
     181    $source_image = @imagecreatefrompng($source_filepath); 
    182182  } 
    183183  else 
     
    258258} 
    259259 
     260function upload_square_resize_im($source_filepath, $destination_filepath, $max_width, $max_height, $quality, $strip_metadata=false) 
     261{ 
     262  // extension of the picture filename 
     263  $extension = strtolower(get_extension($source_filepath)); 
     264  if (!in_array($extension, array('jpg', 'jpeg', 'png'))) 
     265  { 
     266    die('[Imagick] unsupported file extension'); 
     267  } 
     268 
     269  $image = new Imagick($source_filepath); 
     270 
     271  $rotation = get_rotation_angle($source_filepath); 
     272   
     273  // width/height 
     274  $source_width  = $image->getImageWidth(); 
     275  $source_height = $image->getImageHeight(); 
     276 
     277  // Crop image -> square 
     278  $x = 0; 
     279  $y = 0; 
     280  if($source_width > $source_height) 
     281  { 
     282    $x = ceil(($source_width - $source_height) / 2 ); 
     283    $source_width = $source_height; 
     284  } 
     285  elseif ($source_height > $source_width) 
     286  { 
     287    $y = ceil(($source_height - $source_width) / 2); 
     288    $source_height = $source_width; 
     289  } 
     290  $image->cropImage($source_width, $source_height, $x, $y); 
     291   
     292  $resize_dimensions = get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation); 
     293 
     294  // testing on height is useless in theory: if width is unchanged, there 
     295  // should be no resize, because width/height ratio is not modified. 
     296  if ($resize_dimensions['width'] == $source_width and $resize_dimensions['height'] == $source_height) 
     297  { 
     298    // the image doesn't need any resize! We just copy it to the destination 
     299    copy($source_filepath, $destination_filepath); 
     300    return true; 
     301  } 
     302 
     303  $image->setImageCompressionQuality($quality); 
     304  $image->setInterlaceScheme(Imagick::INTERLACE_LINE); 
     305   
     306  if ($strip_metadata) 
     307  { 
     308    // we save a few kilobytes. For example a thumbnail with metadata 
     309    // weights 25KB, without metadata 7KB. 
     310    $image->stripImage(); 
     311  } 
     312   
     313  $image->resizeImage($resize_dimensions['width'], $resize_dimensions['height'], Imagick::FILTER_LANCZOS, 0.9); 
     314 
     315  if (isset($rotation)) 
     316  { 
     317    $image->rotateImage(new ImagickPixel(), -$rotation); 
     318    $image->setImageOrientation(Imagick::ORIENTATION_TOPLEFT); 
     319  } 
     320 
     321  $image->writeImage($destination_filepath); 
     322  $image->destroy(); 
     323 
     324  // everything should be OK if we are here! 
     325  return true; 
     326} 
     327 
    260328add_event_handler('thumbnail_resize', 'thumbnail_square_resize', 40, 5); 
    261329add_event_handler('upload_thumbnail_resize', 'upload_square_resize', 40, 6); 
  • extensions/square_thumbnails/trunk/photo_add_settings.php

    r9754 r9756  
    4343 
    4444// Template init 
    45 $template->assign('SQUARE', $conf['upload_form_thumb_square']); 
     45$template->assign('SQUARE', @$conf['upload_form_thumb_square']); 
    4646 
    4747// Add prefilter 
Note: See TracChangeset for help on using the changeset viewer.