Resizing working very slow

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
blublu
Posts: 3
Joined: 2012-11-20T14:10:57-07:00
Authentication code: 6789

Resizing working very slow

Post by blublu » 2012-11-20T14:17:58-07:00

Hello,
I decided to change my resize functions to Image Magick to get better quality. I also read that IM is much faster than GD but in my case it's running extremely slow. When I upload jpg photo about 2MB size it takes 10 to 20 seconds to resize it! When I do the same with GD (with unsharp mask also) it takes 2 seconds.
I use commands like this:

Code: Select all

convert file.jpg -filter Lanczos -resize 950x500 -quality 85 -unsharp 0x0.75+0.75+0.008 file950.jpg
Is everything ok here or some part should be changed to make it faster?

I use good web server so it shouldn't be a problem. Anyway I've sent a question to the provider also.
Thank you very much for help!
Bartek

Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Resizing working very slow

Post by Bonzo » 2012-11-20T14:55:38-07:00

Try:

Code: Select all

convert -define jpeg:size=950x500 file.jpg -filter Lanczos -resize 950x500 -quality 85 -unsharp 0x0.75+0.75+0.008 file950.jpg
I have some speed tests on my site and depending on the image size and what you are doing Imagick, Imagemagick and GD can be come in different places in speed tests. Imagick may be faster when using php but the documentation is not very good and it will be a lot of trial and error to get what you want - it may not even be installed on your server.

With large images GD can crash as it runs out of memory.

The 20 seconds sounds very slow to me - what version of IM do you have?

henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: Resizing working very slow

Post by henrywho » 2012-11-20T17:27:33-07:00


User avatar
fmw42
Posts: 25588
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resizing working very slow

Post by fmw42 » 2012-11-20T17:48:37-07:00

GD is using a very simple filter and will therefore run faster. You can change the IM filter to point or triangle, such as GD is probably using. But IM can give much better quality. Depends upon what you need for the job. Also you have added unsharp filtering. Thus making it even slower.

-unsharp 0x0.75+0.75+0.008 Are all these parameters meaningful to your process. Do you need them all? Do you know what each is doing? Perhaps a simpler set of arguments may work as well and speed it up.

The define jpg hint from Bonzo (see http://www.imagemagick.org/Usage/formats/#jpg_read) is probably the best you can do to speed things up if you need all the quality provided by IM's flexibility. Do read the link suggested by henrywho. There is a lot there to absorb.

If you are converting to -quality 85 JPG, then perhaps you don't need the higher quality of the IM lanczos filter nor the unsharp masking. Perhap just a bilinear (triangle) filter will do just as well and if unsharp masking is really needed, then perhaps just the 0xsigma might suffice. It would then run faster.
Last edited by fmw42 on 2012-11-20T19:29:36-07:00, edited 1 time in total.

henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: Resizing working very slow

Post by henrywho » 2012-11-20T19:00:44-07:00

Agreed with fmw42.

A sharpened JPEG saved at a lower quality may have similar size as a smoother JPEG saved at a higher quality.... but looking much worse.

User avatar
fmw42
Posts: 25588
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Resizing working very slow

Post by fmw42 » 2012-11-20T19:30:43-07:00

What is the issue? Is it just speed? Do you need all that quality? How important is file size as henrywho points out.

blublu
Posts: 3
Joined: 2012-11-20T14:10:57-07:00
Authentication code: 6789

Re: Resizing working very slow

Post by blublu » 2012-11-21T01:21:21-07:00

Thank you for all replies! I will make some tests and let you know about the results.

blublu
Posts: 3
Joined: 2012-11-20T14:10:57-07:00
Authentication code: 6789

Re: Resizing working very slow

Post by blublu » 2012-11-21T07:58:14-07:00

Hello,
Thank you again for your answers. I've made some test and that's what I got:
- I can't see difference in execution time after using define, maybe my pictures are not big enought to make difference obvious,
- triangle filter is too blurry for me, it's faster but quality is not good enough,
- I've copied unsharp arguments from some IM docs as "the best" in someone's opinion, I didn't suppose then that I have to care about execution time. When I changed arguments to 0x0.75 I noticed that it's even slower then with 0x0.75+0.75+0.008 !
- Removing unsharp and changing quality to 95 made the picture blurry and in my opinion much worse quality. What is more the file size is 50% bigger. I will stay with unsharp then.
- As you noticed I don't need Lanczos filter. Default filter (what's it's name?) is faster and quality is good enough for me.

I use ImageMagick 6.7.7-7.

The best compromise between speed and quality which I could get is:

Code: Select all

convert -define jpeg:size=950x500  1.JPG -resize 950x500 -quality 85 -unsharp 0x0.75+0.75+0.008 1im-mix.jpg
It's much faster but sometimes it still takes 10 seconds. Maybe it's my provider problem, I've to check it.
If you have more ideas, please write it here :)

Thank you very much for help!

Post Reply