Page 1 of 1

GIF crop problem

Posted: 2009-01-26T16:50:10-07:00
by Mumonkan
not sure if this is related to the GIF *resize* bug that is mentioned just recently here, but i have the latest build (6.4.8-9) of imagemagick, and i am seeing problems when i use "crop" on a gif. namely, the visible part of the image is the correct size, but the image itself (page size, i guess) is the original source image size.

i have created a page giving an example of the problem i am seeing.

thanks much for any feedback/help!

-jon

Re: GIF crop problem

Posted: 2009-01-26T16:56:04-07:00
by rmagick
Mumonkan wrote:not sure if this is related to the GIF *resize* bug that is mentioned just recently here, but i have the latest build (6.4.8-9) of imagemagick, and i am seeing problems when i use "crop" on a gif. namely, the visible part of the image is the correct size, but the image itself (page size, i guess) is the original source image size.

i have created a page giving an example of the problem i am seeing.

thanks much for any feedback/help!

-jon
Try the +repage option. http://www.imagemagick.org/script/comma ... php#repage

Re: GIF crop problem

Posted: 2009-01-26T17:14:10-07:00
by Mumonkan
wow, hm... that seems to solve the problem.

now i just need to figure out how to bubble this up into drupal code, where it is being called from. i guess it could get scary from this point out... haha

thanks!!

-jon

Re: GIF crop problem

Posted: 2009-01-26T23:08:02-07:00
by anthony
Cropping GIF animations are triky as it is NOT a single image

+repage is probably not a good solution.

See IM Examples, GIF Animation Modification.
http://www.imagemagick.org/Usage/anim_mods/

the first few examples has general GIF animation handling techniques methods and includes cropping. Later example goes into more difficult and complex problems.

Re: GIF crop problem

Posted: 2009-01-27T16:37:22-07:00
by rmagick
I guess I'm confused. The way I read the OP's question, GIF animations are not involved, just a single-frame GIF. What did I overlook?

Re: GIF crop problem

Posted: 2009-01-27T18:54:50-07:00
by anthony
I may have read more into 'GIF' than I should have.

Applogies.

Re: GIF crop problem

Posted: 2012-04-18T14:33:27-07:00
by cesareof
I had a similar issue cropping gifs that left the canvas the original size using the Magick++ API in C++, code looks like this:

Code: Select all

bool CropImage(char cFileIn[], char cFileOut[], int nNewWidth, int nNewHeight )
{
	bool bRet = false;
	char cLog[MAX_STRING_LARGE];
	int nWidth;
	int nHeight;

	try
	{
		cLog[0] = NULL;
		Image img_Cropped;
		img_Cropped.read(cFileIn);

		//Get width and height of original image
		nWidth = (int)img_Cropped.columns();
		nHeight = (int)img_Cropped.rows();
	
		while (1)
		{
			if( (nNewWidth > nWidth) || (nNewHeight > nHeight)) //IF the cropped section overruns the image height or width 
				break;

			img_Cropped.crop(Geometry(nNewWidth, nNewHeight, 0, 0 ));
			img_Cropped.page(Geometry(nNewWidth, nNewHeight, 0, 0 ));

			// save
			img_Cropped.write(cFileOut);
			bRet = true;
			break;
		}
	}
	catch(Exception &error_ )
	{
		sprintf_s( cLog, MAX_STRING_LARGE, "Caught Exception: %s", error_.what() );
	}
	return bRet;
}

Re: GIF crop problem

Posted: 2012-04-18T19:40:46-07:00
by anthony
That is standard!!!! -crop preserves the original virtual canvas
Remove it with +repage

http://www.imagemagick.org/Usage/crop/#crop

NOTE: In IMv7 the -crop operator may do this automatically with a +crop varient preserving the original canvas. It is on my ToDo list! It will not change in IMv6