Ignore:
Timestamp:
Mar 18, 2011, 2:55:32 PM (13 years ago)
Author:
patdenice
Message:

Create trunk and branch directories

Location:
extensions/square_thumbnails
Files:
3 added
6 copied
6 moved

Legend:

Unmodified
Added
Removed
  • extensions/square_thumbnails/branch/2.1/functions.inc.php

    r9753 r9754  
    152152  }
    153153
     154  if (is_imagick())
     155  {
     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);
     161  }
     162}
     163
     164function upload_square_resize_gd($result, $source_filepath, $destination_filepath, $max_width, $max_height, $quality)
     165{
    154166  if (!function_exists('gd_info'))
    155167  {
     
    163175  if (in_array($extension, array('jpg', 'jpeg')))
    164176  {
    165     $source_image = @imagecreatefromjpeg($source_filepath);
     177    $source_image = imagecreatefromjpeg($source_filepath);
    166178  }
    167179  else if ($extension == 'png')
    168180  {
    169     $source_image = @imagecreatefrompng($source_filepath);
     181    $source_image = imagecreatefrompng($source_filepath);
    170182  }
    171183  else
    172184  {
    173185    die('unsupported file extension');
     186  }
     187
     188  $rotation = null;
     189  if (function_exists('imagerotate'))
     190  {
     191    $rotation = get_rotation_angle($source_filepath);
    174192  }
    175193 
     
    191209  }
    192210 
    193   $ratio_width  = $source_width / $max_width;
    194   $ratio_height = $source_height / $max_height;
    195  
    196   // maximal size exceeded ?
    197   if ($ratio_width > 1 or $ratio_height > 1)
    198   {
    199     if ($ratio_width < $ratio_height)
    200     {
    201       $destination_width = ceil($source_width / $ratio_height);
    202       $destination_height = $max_height;
    203     }
    204     else
    205     {
    206       $destination_width = $max_width;
    207       $destination_height = ceil($source_height / $ratio_width);
    208     }
    209   }
    210   else
     211  $resize_dimensions = get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation);
     212
     213  // testing on height is useless in theory: if width is unchanged, there
     214  // should be no resize, because width/height ratio is not modified.
     215  if ($resize_dimensions['width'] == $source_width and $resize_dimensions['height'] == $source_height)
    211216  {
    212217    // the image doesn't need any resize! We just copy it to the destination
     
    215220  }
    216221 
    217   $destination_image = imagecreatetruecolor($destination_width, $destination_height);
     222  $destination_image = imagecreatetruecolor($resize_dimensions['width'], $resize_dimensions['height']);
    218223 
    219224  imagecopyresampled(
     
    224229    $x,
    225230    $y,
    226     $destination_width,
    227     $destination_height,
     231    $resize_dimensions['width'],
     232    $resize_dimensions['height'],
    228233    $source_width,
    229234    $source_height
    230235    );
    231  
    232   imagejpeg($destination_image, $destination_filepath, $quality);
     236
     237  // rotation occurs only on resized photo to avoid useless memory use
     238  if (isset($rotation))
     239  {
     240    $destination_image = imagerotate($destination_image, $rotation, 0);
     241  }
     242 
     243  $extension = strtolower(get_extension($destination_filepath));
     244  if ($extension == 'png')
     245  {
     246    imagepng($destination_image, $destination_filepath);
     247  }
     248  else
     249  {
     250    imagejpeg($destination_image, $destination_filepath, $quality);
     251  }
    233252  // freeing memory ressources
    234253  imagedestroy($source_image);
  • extensions/square_thumbnails/trunk/functions.inc.php

    r9753 r9754  
    152152  }
    153153
     154  if (is_imagick())
     155  {
     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);
     161  }
     162}
     163
     164function upload_square_resize_gd($result, $source_filepath, $destination_filepath, $max_width, $max_height, $quality)
     165{
    154166  if (!function_exists('gd_info'))
    155167  {
     
    163175  if (in_array($extension, array('jpg', 'jpeg')))
    164176  {
    165     $source_image = @imagecreatefromjpeg($source_filepath);
     177    $source_image = imagecreatefromjpeg($source_filepath);
    166178  }
    167179  else if ($extension == 'png')
    168180  {
    169     $source_image = @imagecreatefrompng($source_filepath);
     181    $source_image = imagecreatefrompng($source_filepath);
    170182  }
    171183  else
    172184  {
    173185    die('unsupported file extension');
     186  }
     187
     188  $rotation = null;
     189  if (function_exists('imagerotate'))
     190  {
     191    $rotation = get_rotation_angle($source_filepath);
    174192  }
    175193 
     
    191209  }
    192210 
    193   $ratio_width  = $source_width / $max_width;
    194   $ratio_height = $source_height / $max_height;
    195  
    196   // maximal size exceeded ?
    197   if ($ratio_width > 1 or $ratio_height > 1)
    198   {
    199     if ($ratio_width < $ratio_height)
    200     {
    201       $destination_width = ceil($source_width / $ratio_height);
    202       $destination_height = $max_height;
    203     }
    204     else
    205     {
    206       $destination_width = $max_width;
    207       $destination_height = ceil($source_height / $ratio_width);
    208     }
    209   }
    210   else
     211  $resize_dimensions = get_resize_dimensions($source_width, $source_height, $max_width, $max_height, $rotation);
     212
     213  // testing on height is useless in theory: if width is unchanged, there
     214  // should be no resize, because width/height ratio is not modified.
     215  if ($resize_dimensions['width'] == $source_width and $resize_dimensions['height'] == $source_height)
    211216  {
    212217    // the image doesn't need any resize! We just copy it to the destination
     
    215220  }
    216221 
    217   $destination_image = imagecreatetruecolor($destination_width, $destination_height);
     222  $destination_image = imagecreatetruecolor($resize_dimensions['width'], $resize_dimensions['height']);
    218223 
    219224  imagecopyresampled(
     
    224229    $x,
    225230    $y,
    226     $destination_width,
    227     $destination_height,
     231    $resize_dimensions['width'],
     232    $resize_dimensions['height'],
    228233    $source_width,
    229234    $source_height
    230235    );
    231  
    232   imagejpeg($destination_image, $destination_filepath, $quality);
     236
     237  // rotation occurs only on resized photo to avoid useless memory use
     238  if (isset($rotation))
     239  {
     240    $destination_image = imagerotate($destination_image, $rotation, 0);
     241  }
     242 
     243  $extension = strtolower(get_extension($destination_filepath));
     244  if ($extension == 'png')
     245  {
     246    imagepng($destination_image, $destination_filepath);
     247  }
     248  else
     249  {
     250    imagejpeg($destination_image, $destination_filepath, $quality);
     251  }
    233252  // freeing memory ressources
    234253  imagedestroy($source_image);
Note: See TracChangeset for help on using the changeset viewer.