Page 1 of 1

How to "force" width and height in AdaptativeResize method

Posted: 2014-07-11T13:02:18-07:00
by JoaoFranco

We have an application responsible for resizing images that are uploaded by the users. The new dimensions are predefined and for each uploaded image, the application creates a new image file for each of the predefined dimensions.

The problem is: The dimensions of the new images doesn't match the values that were specified to the resize method. For example:

Code: Select all

image.AdaptiveResize(60, 45);
The informed values are 60x45, but the image generated is 60x38, 60x36, etc... depending on the dimensions of the original image.
At first, I tried the .Resize method instead of .AdaptativeResize, but the result was the same. Since I wasn't sure if this is the expected behavior or not, I searched the documentation but couldn't understand the situation yet.
Do you guys know if there is a way to 'force' the new image to respect the determined width and height or not? Bellow is the application code:

Code: Select all

using (MagickImage image = new MagickImage(originalImagePath))
                image.Format = MagickFormat.Pjpeg;
                image.AnimationDelay = 50;
                image.Quality = 60;
                image.Depth = 8;    

                image.AdaptiveResize(newWidth, newHeight);               

                using (FileStream fs = new FileStream(newImagePath, FileMode.Create))
Thanks in advance,

Re: How to "force" width and height in AdaptativeResize meth

Posted: 2014-07-11T15:29:48-07:00
by snibgo
I don't know about magick.NET. At the command line, you need to add an exclamation mark to get exactly the required size, eg:

Code: Select all

convert in.png -adaptive-resize 60x45! out.png

Re: How to "force" width and height in AdaptativeResize meth

Posted: 2014-07-14T07:23:14-07:00
by JoaoFranco
Thanks snibgo!

With your information I was able to find the proper .Net code.

Code: Select all

var newImageSize = new MagickGeometry(newWidth, newHeight);
newImageSize.IgnoreAspectRatio = true;