After upload, the gif is resized but the animation is lost. What am I doing wrong?
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(); }
No exception caught.
Array
(
[versionNumber] => 1608
[versionString] => ImageMagick 6.4.8 2011-03-20 Q16 OpenMP http://www.imagemagick.org
)
Try this: http://www.php.net/manual/en/imagick.coalesceimages.php
The first comment seems like what u need. And u should never mix GD2 library ("imagecreatefromgif") and Imagick.
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);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.