Convert -Resize Freezes
Convert -Resize Freezes
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
http://stackoverflow.com/questions/5650 ... loop-hangs
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert -Resize Freezes
#! /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
Re: Convert -Resize Freezes
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
Thanks for the help. Version info:
IM Version: 6.4.0 Q16
OS: cygwin 1.7.9 on Windows 7
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert -Resize Freezes
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?
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?
Re: Convert -Resize Freezes
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.
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.
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert -Resize Freezes
Are you sure that you are using IM convert and Windows convert. From the shell what do you get from
convert -version
convert -version
Re: Convert -Resize Freezes
ImageMagick 6.4.0
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Convert -Resize Freezes
You can not use > in shell for numerical comparision UNLESS it is in a BASH [[...]] construct!
Also using
doesn't make much sense! Why not just use ./raw/*.jpg direct!
Last your convert should read the image FIRST then do the operations...
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!
Code: Select all
if [ "$fwidth" -gt 1000 ] || [ "$fheight" -gt 1000 ]; then
Code: Select all
$(find . -wholename "./raw/*.jpg");
Code: Select all
for f in ./raw/*.jpg; do
Code: Select all
convert "$f" -resize 60% -quality 92 -unsharp 0x0.5 "${outputdir}/${filename}"
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/
https://imagemagick.org/Usage/
Re: Convert -Resize Freezes
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.
Also, the reason I'm using find is so that it searches sub-directories.
Re: Convert -Resize Freezes
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:
After doing this, I never came accross this issue anymore - so it's most likely related to the cygwin build that is used.
so my call is for instance:
Code: Select all
c:/path/to/ImageMagick/convert.exe -resize 900x600 input.jpg ./resize/output.jpg
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: Convert -Resize Freezes
Yes, Cygwin needs unix forward slashes and not windows back slashes, as far a I understand.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:After doing this, I never came accross this issue anymore - so it's most likely related to the cygwin build that is used.Code: Select all
c:/path/to/ImageMagick/convert.exe -resize 900x600 input.jpg ./resize/output.jpg
- anthony
- Posts: 8883
- Joined: 2004-05-31T19:27:03-07:00
- Authentication code: 8675308
- Location: Brisbane, Australia
Re: Convert -Resize Freezes
Congratulations.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:After doing this, I never came accross this issue anymore - so it's most likely related to the cygwin build that is used.Code: Select all
c:/path/to/ImageMagick/convert.exe -resize 900x600 input.jpg ./resize/output.jpg
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/
https://imagemagick.org/Usage/