1

上传后,gif 会调整大小,但动画会丢失。我究竟做错了什么?

try
{
   $animation = new Imagick($this->image_filename);

   foreach ($animation as $frame)
   {
      $frame->thumbnailImage($width, $height);
      $frame->setImagePage($width, $height, 0, 0);
   }

   $animation->writeImages($this->image_filename, true);

   echo "<img src='".$this->image_filename."' />";

   $this->image = imagecreatefromgif($this->image_filename);
}
catch(Exception $e){ echo $e->getMessage(); }

没有发现异常。

Array
(
    [versionNumber] => 1608
    [versionString] => ImageMagick 6.4.8 2011-03-20 Q16 OpenMP http://www.imagemagick.org
)
4

2 回答 2

3

试试这个:http
://www.php.net/manual/en/imagick.coalesceimages.php 第一条评论似乎是你需要的。而且你不应该混合 GD2 库(“imagecreatefromgif”)和 Imagick。

于 2013-08-26T05:16:09.637 回答
1

我使用了这个功能:

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);

}

于 2017-05-09T11:23:00.400 回答