resize animated gif
Posted: 2012-06-13T04:04:53-07:00
Hi there,
i have problem with resize animated gif.
i want to resize this image
and i have resize result :
i see that the equalizer position is wrong. is there any way to get actual frame position in image and scale it correctly
thank you
jimmy
here my script
i have problem with resize animated gif.
i want to resize this image
and i have resize result :
i see that the equalizer position is wrong. is there any way to get actual frame position in image and scale it correctly
thank you
jimmy
here my script
Code: Select all
<?php
$im = new Imagick( "test.gif" );
header( "Content-Type: image/gif" );
echo resizeAnimGif("test.gif",300, 50, 216, 36);
function resizeAnimGif($file, $oldWidth, $oldHeight, $newWidth, $newHeight) {
try
{
/*** Read in the animated gif ***/
$animation = new Imagick($file);
$ratiox = $newWidth / $oldWidth;
$ratioy = $newHeight / $oldHeight;
/*** Loop through the frames ***/
foreach ($animation as $frame)
{
$img = $frame->getImagePage();
$imgFrame = $frame->getImageGeometry();
$newx = round ($img['x'] * $ratiox );
$newy = round ($img['y'] * $ratioy );
$nWidth = round($imgFrame['width'] * $ratiox );
$nHeight = round($imgFrame['height'] * $ratioy );
/*** Thumbnail each frame ***/
$frame->thumbnailImage($nWidth, $nHeight);
/*** Set virtual canvas size to 100x100 ***/
$frame->setImagePage($nWidth, $nHeight, $newx, $newy);
}
return $animation->getImagesBlob();
}
catch(Exception $e)
{
return false;
}
}
?>