簡體   English   中英

php ImageMagick gif resize保持動畫

[英]php ImageMagick gif resize keep animation

上傳后,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
)

試試這個: http//www.php.net/manual/en/imagick.coalesceimages.php
第一條評論看起來像你需要的。 你永遠不應該混合GD2庫(“imagecreatefromgif”)和Imagick。

我用過這個函數:

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

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM