How to "force" width and height in AdaptativeResize method

Magick.NET is an object-oriented C# interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick.NET
Locked
JoaoFranco
Posts: 2
Joined: 2014-07-11T12:22:40-07:00
Authentication code: 6789

How to "force" width and height in AdaptativeResize method

Post by JoaoFranco »

Hi,

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))
                {  
                    image.Write(fs);
                }
            }
Thanks in advance,

snibgo
Posts: 13034
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

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

Post 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
snibgo's IM pages: im.snibgo.com

JoaoFranco
Posts: 2
Joined: 2014-07-11T12:22:40-07:00
Authentication code: 6789

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

Post 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;
image.AdaptiveResize(newImageSize);

Locked