0

I want to resize the gif file without losing animation using php script. I tried but the animation failed on the resized GIF image.

I tried this code

http://www.white-hat-web-design.co.uk/blog/resizing-images-with-php/

user1258544
  • 263
  • 1
  • 4
  • 11
  • possible duplicate of [Resize animated gif file without destroying animation](http://stackoverflow.com/questions/718491/resize-animated-gif-file-without-destroying-animation) – Lawrence Cherone Aug 23 '13 at 06:24
  • http://www.phpclasses.org/package/7353-PHP-Resize-animations-in-files-of-the-GIF-format.html – ak-SE Jan 21 '16 at 14:16

1 Answers1

0

I used this function :

function gifResize($file_origin,$file_dest,$percent){
   $percent = $percent*100;
   $crop_w = 0;
   $crop_h = 0;
   $crop_x = 0;
   $crop_y = 0;
   $image = new Imagick($file_origin);
   $originalWidth = $image->getImageWidth();
   $originalHeight = $image->getImageHeight();
   $size_w = ($originalWidth*$percent)/100;
   $size_h = ($originalHeight*$percent)/100;
   if(($size_w-$originalWidth)>($size_h-$originalHeight)){
       $s = $size_h/$originalHeight;
       $size_w = round($originalWidth*$s);
       $size_h = round($originalHeight*$s);
   }else{
       $s = $size_w/$originalWidth;
       $size_w = round($originalWidth*$s);
       $size_h = round($originalHeight*$s);
   }
   echo "$originalWidth $size_w - $originalHeight $size_h";
   $image = $image->coalesceImages();

   foreach ($image as $frame) {
       $frame->cropImage($crop_w, $crop_h, $crop_x, $crop_y);
       $frame->thumbnailImage($size_h, $size_w);
       $frame->setImagePage($size_h, $size_w, 0, 0);
   }
   $imageContent = $image->getImagesBlob();
   $fp = fopen($file_dest,'w');
   fwrite($fp,$imageContent);
   fclose($fp);
}