Page 1 of 1

Problem in resize image percentage wise.

Posted: 2017-04-27T00:58:01-07:00
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();
}

Re: Problem in resize image percentage wise.

Posted: 2017-04-27T02:20:17-07:00
by rpatelob
I got the solution. I just need to call MagickScaleImage(wand, width, height); function exactly after MagickResizeImage(wand, newWidth, newHeight, 0); function.

Re: Problem in resize image percentage wise.

Posted: 2017-04-27T05:35:35-07:00
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);

Re: Problem in resize image percentage wise.

Posted: 2017-04-28T03:01:44-07:00
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.