This project has moved. For the latest updates, please go here.

Resizing image without keeping aspet ratio

Jun 13, 2013 at 7:28 PM
Hi,
First of all thanks for this library.

I implemented Magick.net 6.8.5.4 in order to resize image on the fly on my website.
All was working perfectly but i just figure that some images were not at the specific size that i wanted.
For example, i have a wall of image and all images must have a width of 272px. And for some image when i resize the library take the liberty of resizing to 271 px.

I don't understand why, and how can i force that.?

Here is a sample of my code :
Width = 272 px and Height = 349 in this case.
MemoryStream resultStream = new MemoryStream();
           
MagickImage mimg = new MagickImage(imgStream);

mimg.Resize(width, height);

mimg.ImageType = ImageType.Jpeg;
mimg.Quality = 95;
mimg.Write(resultStream);
mimg.Dispose();
The result is that the MagickImage instance has a size of 271px x 349px

Is there a way to keep the image at the size wanted ? What i missing here ?

Thanks a lot for reading this, and sorry for my pour english.

Alex
Coordinator
Jun 14, 2013 at 5:34 AM
Edited Jun 14, 2013 at 6:13 AM
Do you want all images to have the same width? Or do you want your image to fit within (272x349)?
Jun 14, 2013 at 11:11 AM
I would like to have the same width.
In fact, height is determined by a ratio compute from the original image, the real obligation is to obtain an image with a width of 272 px.

I have the feeling that my ratio compute that determine the 349px of height for this specific image is different than the one used by imageMagick..
And maybe it is why the result after resize is 271x349.. i don't know.

Thx for the help much appreciated.


Alex
Coordinator
Jun 14, 2013 at 11:42 AM
You don't need to compute it yourself. When you specify 0 for the height, it will be calculated by Magick.NET.
Jun 14, 2013 at 12:01 PM
Thanks for the information :)
But in the project, i have to do this before for different reasons, but maybe in this case i shouldn't use the result and use the height = 0.
Anyway i finally found a problem in my ratio method, i made a "round shortcut" and it resulted with bad height round.. It explains the difference between me and Magick :)

Thx a lot for your answers.