Hi All,
Like my previous thread dealing with caption, is there a way for ImageMagick to resize an image more quickly and efficiently? Of all the measurements I've taken, the resize operation takes about 400MS which is longer than everything else being done in my app using ImageMagick.
I need to optimize for speed and efficiency.
Speed Up Resize Operation?
Re: Speed Up Resize Operation?
What code are you currently using, platform and language?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Speed Up Resize Operation?
Try -scale rather than -resize. Or add -filter point before -resize. Or use -thumbnail. If you have lots of meta data or profiles, the -thumbnail will remove them. You could also add -strip after reading your input and before -resize.
Re: Speed Up Resize Operation?
Scale appears to be several times faster and appears to produce similar results. Thanks fmw42.
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Speed Up Resize Operation?
"-sample" is even quicker, but may not give you acceptable results.
snibgo's IM pages: im.snibgo.com
Re: Speed Up Resize Operation?
Yeah, sample wasn't respecting the image aspect ratio? I am resizing 400 x 400 in my example, but the picture is not square. When I use resize or scale, the image is resized to a height of 400 and a width of 283 which is correct for its aspect. Sample does 400 x 400 without preserving the aspect?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Speed Up Resize Operation?
"-sample" should give the same size output as "-resize" or "-scale", given the same input image and geometry argument.
What version IM are you using?
What version IM are you using?
snibgo's IM pages: im.snibgo.com
Re: Speed Up Resize Operation?
You're right. It looks like a bug in the Magick.NET wrapper. When I run ImageMagick from the commandline sample does maintain the aspect ratio. I wonder how Magick.NET could even be overwriting this default sample behavior?
Sample doesn't produce great results, but man is it fast! It takes 6 milliseconds to sample resize. Scale takes 200MS, and Resize takes 500+ depending on the image. Is there anything between scale and sample? 200MS is still kind of a long time for this operation.
Sample doesn't produce great results, but man is it fast! It takes 6 milliseconds to sample resize. Scale takes 200MS, and Resize takes 500+ depending on the image. Is there anything between scale and sample? 200MS is still kind of a long time for this operation.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Speed Up Resize Operation?
Not that I know. You could try -filter point -thumbnail, but I suspect it will be longer than -scale.Is there anything between scale and sample? 200MS is still kind of a long time for this operation.
What percent size reduction are you making?
-
- Posts: 12159
- Joined: 2010-01-23T23:01:33-07:00
- Authentication code: 1151
- Location: England, UK
Re: Speed Up Resize Operation?
Sorry, I don't use MagickNET. I use SampleImage() at the MagickCore level, which works fine.
Sampling is very fast because it doesn't calculate new colours for output pixels. It simply picks the colour of an input pixel. For some purposes, eg zooming in to an image to get "big pixels", or flat-colour graphics, it's the right tool.
I'm not aware of anything between scale and sample. There may be another way to increase performance, eg we sometimes resize then crop when it's faster to crop first and then resize.
Sampling is very fast because it doesn't calculate new colours for output pixels. It simply picks the colour of an input pixel. For some purposes, eg zooming in to an image to get "big pixels", or flat-colour graphics, it's the right tool.
I'm not aware of anything between scale and sample. There may be another way to increase performance, eg we sometimes resize then crop when it's faster to crop first and then resize.
snibgo's IM pages: im.snibgo.com