Convert -Resize Freezes

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
hmc2323
Posts: 5
Joined: 2011-04-13T10:02:42-07:00
Authentication code: 8675308

Convert -Resize Freezes

Post by hmc2323 »

I wrote a script to loop through files in a folder and resize them. The convert command freezes on some of the images for a long time. I posted on Stack Overflow:

http://stackoverflow.com/questions/5650 ... loop-hangs
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert -Resize Freezes

Post by fmw42 »

#! /bin/bash

for f in $(find . -wholename "./raw/*.jpg"); do
# fwidth, fheight, outputdir, filename variables defined...

if [ "$fwidth" -gt 1000 ] || [ "$fheight" -gt 1000 ]; then
convert -resize 60% -quality 92 -unsharp 0x0.5 $f ${outputdir}/${filename};
else
cp $f ${outputdir}/${filename};
fi
done

First you have not said what version of IM and what platform and how much memory you have.

I can see several possible issues (though my unix is rather primitive - so I will assume your for command is fine). Try

#! /bin/bash

for f in $(find . -wholename "./raw/*.jpg"); do
# fwidth, fheight, outputdir, filename variables defined...

if [ "$fwidth" > "1000" -o "$fheight" > "1000" ]; then
convert $f -resize 60% -unsharp 0x0.5 -quality 92 ${outputdir}/${filename};
else
cp $f ${outputdir}/${filename};
fi
done
hmc2323
Posts: 5
Joined: 2011-04-13T10:02:42-07:00
Authentication code: 8675308

Re: Convert -Resize Freezes

Post by hmc2323 »

I tried those code changes and still got hung up after processing some images. As far as I can tell those were just syntax suggestions, is that right?

Thanks for the help. Version info:
IM Version: 6.4.0 Q16
OS: cygwin 1.7.9 on Windows 7
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert -Resize Freezes

Post by fmw42 »

Perhaps your Cygwin install is the issue.

But note that IM 6 syntax should in this case have the input image right after convert. Though backward compatibility usually works anyway.

Have you tried simplifying your command line to see which command might be the cause? Have you tried just running the command line on the images that fail without the looping and condition script?

Try to get to the root of the issue.

Do you have enough memory for the size images?

Is it possible that some of your images are corrupt?
hmc2323
Posts: 5
Joined: 2011-04-13T10:02:42-07:00
Authentication code: 8675308

Re: Convert -Resize Freezes

Post by hmc2323 »

Yes I can try VirtualBox instead of Cygwin to see if that helps. Yes the command that is the cause (or at least the command that freezes) is the "convert" line. My computer seems to be at 60% CPU (which is higher than baseline). Once I get an image that freezes I have tried running the convert command directly from shell and it freezes. Interestingly I can get it to work by making small changes such as changing the output directory.

The images are no more than 200k in size and my memory/cpu usage is not near 100%. I don't know how to test if the images are corrupt. I am able to open the images that freeze without trouble.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert -Resize Freezes

Post by fmw42 »

Are you sure that you are using IM convert and Windows convert. From the shell what do you get from

convert -version
hmc2323
Posts: 5
Joined: 2011-04-13T10:02:42-07:00
Authentication code: 8675308

Re: Convert -Resize Freezes

Post by hmc2323 »

ImageMagick 6.4.0
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Convert -Resize Freezes

Post by anthony »

You can not use > in shell for numerical comparision UNLESS it is in a BASH [[...]] construct!

Code: Select all

   if [ "$fwidth" -gt 1000 ] || [ "$fheight" -gt 1000 ]; then
Also using

Code: Select all

$(find . -wholename "./raw/*.jpg");
doesn't make much sense! Why not just use ./raw/*.jpg direct!

Code: Select all

for f in ./raw/*.jpg; do
Last your convert should read the image FIRST then do the operations...

Code: Select all

convert  "$f" -resize 60% -quality 92 -unsharp 0x0.5 "${outputdir}/${filename}"
the quotes are important if your filenames contain spaces or other strange characters!

The actual problem about FREZING, however is probably caused by LARGE images forcing ImageMagick to switch from 'in-memory' processing to 'disk-cache' processing. The later being VERY VERY SLOW!
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
hmc2323
Posts: 5
Joined: 2011-04-13T10:02:42-07:00
Authentication code: 8675308

Re: Convert -Resize Freezes

Post by hmc2323 »

Thank you. These files are not too large (200kb at most and max width/height of 1100 pixels). Is there a way to force ImageMagick to use in-memory processing only (and restrict the total amount of memory it consumes)?

Also, the reason I'm using find is so that it searches sub-directories.
jjik
Posts: 1
Joined: 2011-09-22T01:51:13-07:00
Authentication code: 8675308

Re: Convert -Resize Freezes

Post by jjik »

I solved this by downloading a binary distribution for Windows, and referring to it in bash script. Do not use backslash as a directory sign in shell.
so my call is for instance:

Code: Select all

c:/path/to/ImageMagick/convert.exe -resize 900x600 input.jpg ./resize/output.jpg
After doing this, I never came accross this issue anymore - so it's most likely related to the cygwin build that is used.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Convert -Resize Freezes

Post by fmw42 »

jjik wrote:I solved this by downloading a binary distribution for Windows, and referring to it in bash script. Do not use backslash as a directory sign in shell.
so my call is for instance:

Code: Select all

c:/path/to/ImageMagick/convert.exe -resize 900x600 input.jpg ./resize/output.jpg
After doing this, I never came accross this issue anymore - so it's most likely related to the cygwin build that is used.
Yes, Cygwin needs unix forward slashes and not windows back slashes, as far a I understand.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Re: Convert -Resize Freezes

Post by anthony »

jjik wrote:I solved this by downloading a binary distribution for Windows, and referring to it in bash script. Do not use backslash as a directory sign in shell.
so my call is for instance:

Code: Select all

c:/path/to/ImageMagick/convert.exe -resize 900x600 input.jpg ./resize/output.jpg
After doing this, I never came accross this issue anymore - so it's most likely related to the cygwin build that is used.
Congratulations.

Though it does not tell us what was the actual cause, at least you have it solved. You are right in that the file sizes (in pixels not bytes) you mentioned should not have been a disk caching, or system thrashing problem.


However you are still not reading the image before applying the image processing operator! While this worked find for IMv6 it will more than likely fail and error for the IMv7 with a 'no image to process' error. I will be starting programming of the CLI for IMv7 is starting this weekend (if nothing unforeseen happens).
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply