GIF crop problem

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
Post Reply
Mumonkan

GIF crop problem

Post 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
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: GIF crop problem

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

Re: GIF crop problem

Post 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
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: GIF crop problem

Post 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.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Re: GIF crop problem

Post 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?
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: GIF crop problem

Post by anthony »

I may have read more into 'GIF' than I should have.

Applogies.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
cesareof
Posts: 11
Joined: 2011-03-25T08:12:07-07:00
Authentication code: 8675308

Re: GIF crop problem

Post 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;
}
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: GIF crop problem

Post 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
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply