resize animated gif

IMagick is a native PHP extension to create and modify images using the ImageMagick API. ImageMagick Studio LLC did not write nor does it maintain the IMagick extension, however, IMagick users are welcome to discuss the extension here.
Post Reply
jim_muna
Posts: 2
Joined: 2012-06-13T03:01:30-07:00
Authentication code: 13

resize animated gif

Post 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;
		}
	}
?>
DJ Mike
Posts: 33
Joined: 2010-06-29T19:07:53-07:00
Authentication code: 8675308

Re: resize animated gif

Post 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.
DJ Mike's Tutorials: PHP
ImageMagick Functions
http://eclecticdjs.com/mike/tutorials/p ... /index.php
jim_muna
Posts: 2
Joined: 2012-06-13T03:01:30-07:00
Authentication code: 13

Re: resize animated gif

Post 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
Post Reply