My ultimate target is to resize many images maintaining their aspect ratio as well, and if required fill the extra space(padding) with white color.
Please suggest some C API to achieve this.
I tried using MagickResizeImage and MagickScaleImage but both are resulting in blurry images.
When I use "convert -resize 1200x627 Desktop/myntraProd.jpg -gravity center -extent 1200x627 Desktop/myntraProdIMCLI.jpg" this from command line it gives me the desired output.
In short is there a way to resize an image while maintaining the aspect ratio as well.
Any help would be appreciated.
Resize an Image using ImageMagick C API
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Resize an Image using ImageMagick C API
I use these, in resize.h:
They all need the new number of columns and rows, so I need to calculate those.
They work fine, just like the command-line interface, as far as know.
(I mostly use MagickCore. If you use MagickWand, I expect that has suitable wrappers.)
Code: Select all
*ResizeImage(const Image *,const size_t,const size_t,const FilterTypes,
const double,ExceptionInfo *),
*SampleImage(const Image *,const size_t,const size_t,ExceptionInfo *),
*ScaleImage(const Image *,const size_t,const size_t,ExceptionInfo *),
They work fine, just like the command-line interface, as far as know.
(I mostly use MagickCore. If you use MagickWand, I expect that has suitable wrappers.)
snibgo's IM pages: im.snibgo.com
Re: Resize an Image using ImageMagick C API
How do you calculate the new number of columns and rows for the above mentioned methods.
Say, for example I have an image with 1080x1440 dimension and I wanna resize it to 1200x627. So what should be the number of rows and columns that I need to pass to the above methods, so that I get a proper Image with keeping the aspect ratio as well.
Say, for example I have an image with 1080x1440 dimension and I wanna resize it to 1200x627. So what should be the number of rows and columns that I need to pass to the above methods, so that I get a proper Image with keeping the aspect ratio as well.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Resize an Image using ImageMagick C API
Your input image is 1080x1440. You want to resize it to fit into a box that is 1200x627, keeping the aspect ratio. Is that correct?
1200/1080=1.111
627/1440=0.4354
min(1.111, 0.4354) = 0.4354. So that is the magnification factor.
1080 * 0.4354 = 470.232
1440 * 0.4354 = 626.976
Round to the nearest integers, and check that neither is zero: resize to 470x627 pixels.
1200/1080=1.111
627/1440=0.4354
min(1.111, 0.4354) = 0.4354. So that is the magnification factor.
1080 * 0.4354 = 470.232
1440 * 0.4354 = 626.976
Round to the nearest integers, and check that neither is zero: resize to 470x627 pixels.
snibgo's IM pages: im.snibgo.com
Re: Resize an Image using ImageMagick C API
Thanks for the help
Really Appreciate
Really Appreciate