Page 1 of 1

resize animated gif

Posted: 2012-06-13T04:04:53-07:00
by jim_muna
Hi there,

i have problem with resize animated gif.

i want to resize this image Image

and i have resize result :
Image

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;
		}
	}
?>

Re: resize animated gif

Posted: 2012-06-13T09:54:03-07:00
by DJ Mike
Try coalesceImages()

Imagick::coalesceImages
http://us2.php.net/manual/en/imagick.coalesceimages.php

The web page says that coalesceImages() composites the frames but that isn't exactly true. You don't get a single frame as an output. Instead of having frames like a movie, some animations have a fixed background for the first frame followed by a series of frames that may be of different sizes and positions. Coalesce will composite those onto the background so the result has frames all the same size and position like a movie. I use coalesce on all animations before resizing them.

Re: resize animated gif

Posted: 2012-06-14T00:44:28-07:00
by jim_muna
DJ Mike wrote:Try coalesceImages()

Imagick::coalesceImages
http://us2.php.net/manual/en/imagick.coalesceimages.php

The web page says that coalesceImages() composites the frames but that isn't exactly true. You don't get a single frame as an output. Instead of having frames like a movie, some animations have a fixed background for the first frame followed by a series of frames that may be of different sizes and positions. Coalesce will composite those onto the background so the result has frames all the same size and position like a movie. I use coalesce on all animations before resizing them.
i have try this too. but still goes wrong and i noticed that this feature not work in module version 3. here note from phpmanual.net:
This example works fine with *imagick module version 2.2.1-dev*, but doesn't work correctly with *imagick module version 3.0.1*.

i have try to downgrade the module to 2.3.0 , but still not working.

thank you