Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ImageMagick Convert Loop Hangs

Tags:

linux

bash

I am running a script intended to resize all images in a folder and its subdirectories if the dimensions are of a certain size. The script hangs on the "convert" line after getting through about 1,000-2,000 images. (The exact image it hangs on is different every time).

#! /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
like image 504
user706177 Avatar asked Mar 06 '26 05:03

user706177


1 Answers

First of describe in more detail what "hanging" means. Does it stop execution? Does convert work at 100% CPU usage for some time? Something else?

Then start debugging the script. Please add some debugging output and try to run the script with bash -x script.sh which should output all commands actually ran.

#! /bin/bash

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

    if [ "$fwidth" -gt 1000 ] || [ "$fheight" -gt 1000 ]; then
        convert -verbose -resize 60% -quality 92 -unsharp 0x0.5 $f ${outputdir}/${filename};
    else
        cp -v $f ${outputdir}/${filename};
    fi
done
like image 86
Daniel Böhmer Avatar answered Mar 08 '26 22:03

Daniel Böhmer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!