Problem in resize image percentage wise.

The MagickWand interface is a new high-level C API interface to ImageMagick core methods. We discourage the use of the core methods and encourage the use of this API instead. Post MagickWand questions, bug reports, and suggestions to this forum.
Post Reply
rpatelob
Posts: 62
Joined: 2017-04-17T22:17:01-07:00
Authentication code: 1151

Problem in resize image percentage wise.

Post by rpatelob »

Code: Select all

 convert yahoo.jpg -resize 294.105% -background none -extent 1941.09x5663.99 yahootest.png 
I have this command. Now in that command the resize parameter is in percentage so I tried to write same thing using C and below is my code.
The problem with C code is when MagickExtendImage executed the image will be cropped. Because the resize in percentage and pixel are not same. So is there any function or any option in MagickWand C API to resize image percentage wise?

Code: Select all


void test(){
	MagickWand * wand;
	PixelWand * PW1;	
	PW1 = NewPixelWand();
	PixelSetColor(PW1,"none");
	wand = NewMagickWand();	
	MagickReadImage(wand, "yahoo.jpg");
	//get the height and width of an image
	size_t height = MagickGetImageHeight(wand);
	size_t width =  MagickGetImageWidth(wand);
	// new height and width as per the percentage calculation
	size_t newWidth = 294*width/100;
	size_t newHeight = 294*height/100;

	MagickResizeImage(wand, newWidth, newHeight, 0);
	MagickSetImageBackgroundColor(wand, PW1);
	MagickExtentImage(wand,1941,5663,0,0);
	MagickWriteImage(wand,"yahoocheck.png");
	
	wand = DestroyMagickWand(wand);
	DestroyPixelWand(PW1);
	MagickWandTerminus();
}
rpatelob
Posts: 62
Joined: 2017-04-17T22:17:01-07:00
Authentication code: 1151

Re: Problem in resize image percentage wise.

Post by rpatelob »

I got the solution. I just need to call MagickScaleImage(wand, width, height); function exactly after MagickResizeImage(wand, newWidth, newHeight, 0); function.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Problem in resize image percentage wise.

Post by snibgo »

A resize followed by a scale won't give the same result as a single resize.

You want "-resize 294.105%". This would be:

Code: Select all

size_t newWidth = floor(294.105*width/100.0 + 0.5);
size_t newHeight = floor(294.105*height/100.0 + 0.5);
MagickResizeImage(wand, newWidth, newHeight, 0);
snibgo's IM pages: im.snibgo.com
rpatelob
Posts: 62
Joined: 2017-04-17T22:17:01-07:00
Authentication code: 1151

Re: Problem in resize image percentage wise.

Post by rpatelob »

snibgo wrote: 2017-04-27T05:35:35-07:00 A resize followed by a scale won't give the same result as a single resize.

You want "-resize 294.105%". This would be:

Code: Select all

size_t newWidth = floor(294.105*width/100.0 + 0.5);
size_t newHeight = floor(294.105*height/100.0 + 0.5);
MagickResizeImage(wand, newWidth, newHeight, 0);
I have done the same thing but when I call MagickExtentImage(wand,1941,5663,0,0); . the image will be cropped. And If I place the the MagickScaleImage, I would get the expected result.
Post Reply