mogrify take to long on a specific image

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
hugolavalle
Posts: 2
Joined: 2016-09-02T11:12:52-07:00
Authentication code: 1151

mogrify take to long on a specific image

Post by hugolavalle »

Hi,

I've been using IM since 2013 to generate thumbs for images that users posts on my website. Few weeks ago I changed a convert command to mogrify, based on the information on this article: https://www.smashingmagazine.com/2015/0 ... agemagick/

I can say that the result is great, but today I faced a very weird situation. It usualy takes a few seconds to generate every thumb, but I received an image today, that took about 5 minutes to convert.

I appreciate if anyone has any idea.

The image is a jpg, with filesize 346,1 kB, 929x1064 pixels, 96x96ppi, and it's available here: http://bit.ly/2bKNUIn

After some research I discovered the -monitor option, so the command I used is this:

Code: Select all

mogrify -path ./tmp -filter Triangle -define filter:support=2 -thumbnail 448 -unsharp 0.25x0.08+8.3+0.045 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace sRGB -monitor IMG-20160902-WA0002.jpg
And the output was this:

Code: Select all

load image[IMG-20160902-WA0002.jpg]: 1063 of 1064, 100% complete
Resize/Image/./tmp[IMG-20160902-WA0002.jpg]: 960 of 961, 100% complete
Blur/Image/./tmp[IMG-20160902-WA0002.jpg]: 960 of 961, 100% complete
Sharpen/Image/./tmp[IMG-20160902-WA0002.jpg]: 512 of 513, 100% complete
Posterize/Image/./tmp[IMG-20160902-WA0002.jpg]: 512 of 513, 100% complete
Classify/Image/./tmp[IMG-20160902-WA0002.jpg]: 512 of 513, 100% complete
Reduce/Image/./tmp[IMG-20160902-WA0002.jpg]: 6956 of 6957, 100% complete
Assign/Image/./tmp[IMG-20160902-WA0002.jpg]: 512 of 513, 100% complete
Save/Image/./tmp[IMG-20160902-WA0002.jpg]: 512 of 513, 100% complete
I could see that it took a long time on the Reduce. It makes sense

One thing I could see is, if I change the geometry argument of -thumbnail to anything below 417, for example 400, the execution takes about 3 seconds, and I could see that Reduce is not executed:

Code: Select all

load image[IMG-20160902-WA0002.jpg]: 1063 of 1064, 100% complete
Resize/Image/./tmp[IMG-20160902-WA0002.jpg]: 857 of 858, 100% complete
Blur/Image/./tmp[IMG-20160902-WA0002.jpg]: 857 of 858, 100% complete
Sharpen/Image/./tmp[IMG-20160902-WA0002.jpg]: 457 of 458, 100% complete
Posterize/Image/./tmp[IMG-20160902-WA0002.jpg]: 457 of 458, 100% complete
Classify/Image/./tmp[IMG-20160902-WA0002.jpg]: 457 of 458, 100% complete
Assign/Image/./tmp[IMG-20160902-WA0002.jpg]: 457 of 458, 100% complete
Save/Image/./tmp[IMG-20160902-WA0002.jpg]: 457 of 458, 100% completee
Since I started to use this mogrify command, I usually see images a lot larger than this one.

I know that is taking to long on that Reduce step, but I don't know what is the relationship between this step and the -thumbnail argument.

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

Re: mogrify take to long on a specific image

Post by fmw42 »

Mogrify is much older and less optimized that convert. Mogrify was designed to do simple thinks on multiple image. Convert was designed to do complex things on single images. I see no point in switching to mogrify for processing single images. In fact in some cases, you might find writing a loop with convert over multiple images to be better for you with complex operations than mogrify.
hugolavalle
Posts: 2
Joined: 2016-09-02T11:12:52-07:00
Authentication code: 1151

Re: mogrify take to long on a specific image

Post by hugolavalle »

I just showed this post to a friend, and when she tried the conversion was quick. Before I go crazy I started to check what could be diferent, so it was diferent versions of IM

On the environments that I faced the problem the version is 6.7.7-10

Where it runs fast, the version is 6.8.9-9

And here it is the command and output with the new version:

Code: Select all

mogrify -path ./tmp -filter Triangle -define filter:support=2 -thumbnail 448 -unsharp 0.25x0.08+8.3+0.045 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -define png:compression-filter=5 -define png:compression-level=9 -define png:compression-strategy=1 -define png:exclude-chunk=all -interlace none -colorspace sRGB -monitor IMG-20160902-WA0002.jpg
load image[IMG-20160902-WA0002.jpg]: 1063 of 1064, 100% complete
Resize/Image/./tmp[teste.jpg]: 960 of 961, 100% complete
Morphology/Image/./tmp[teste.jpg]: 512 of 513, 100% complete
Sharpen/Image/./tmp[teste.jpg]: 512 of 513, 100% completete
Posterize/Image/./tmp[teste.jpg]: 512 of 513, 100% complete
Classify/Image/./tmp[teste.jpg]: 512 of 513, 100% complete
Assign/Image/./tmp[teste.jpg]: 512 of 513, 100% completeete
Save/Image/./tmp[teste.jpg]: 512 of 513, 100% complete
The new version was installed when upgrading from Ubuntu 14.04 to 16.04

Where can I find the change log of the 6.x versions of IM ?

I saw that the latest is 7.0.2-10. I will research about why Ubuntu uses an old version and if it is safe to install the latest on it.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: mogrify take to long on a specific image

Post by fmw42 »

IM 6.7.7.10 is ancient (about 180 versions old). So it is not surprising that it would be slower or have a bug. You should upgrade to the latest IM 6 or IM 7 versions. The IM 6 changelog is at http://legacy.imagemagick.org/script/changelog.php
cyberbob
Posts: 2
Joined: 2016-04-14T01:47:14-07:00
Authentication code: 1151

Re: mogrify take to LOOONG time under LINUX!

Post by cyberbob »

Dear Sir,
I have more or less THE SAME ISSUE:
LATEST IM version 6.7.7-10 2017-03-14 under LINUX MINT 17.3 MATE (Ubuntu 14.04.3)

Withe my string:

Code: Select all

mogrify -resize 100% -path CompressImage/ -filter Triangle -define filter:support=2 -unsharp 0.25x0.25+8+0.065 -dither None -posterize 136 -quality 82 -define jpeg:fancy-upsampling=off -interlace none -colorspace sRGB *.jpg
I obtain a perfect image with the same pixel resolution with a high compression as MByte of the JPG image!!

On the same hardware, under WINDOWS 7 the comand takes 30 seconds to precess few a test images... under LINUX 14.04 it takes 20 MINUTE per image!!!

You say to use "CONVERT" but with my options I receive an error! also in this topic:
viewtopic.php?t=29473

Could tsome one please, do for me a batch script to use CONVERT command, with my options, to convert ALL the image find in a folder and put the compressed image in /home/mike/CompressImage/ ???

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

Re: mogrify take to long on a specific image

Post by Bonzo »

See my thread here: https://www.imagemagick.org/discourse-s ... =1&t=31875

The latest version is 6.9 something, your 6.7.7-10 2017-03-14 is a patched version of a very old version and the patches do not bring it up to the latest version. I know as I had strange problems that were cured by upgrading.

If you search the forum you should be able to find a batch script you can alter for your needs.
Post Reply