我正在运行一个脚本,用于调整文件夹及其子目录中所有图像的大小(如果尺寸为特定大小)。在处理了大约 1,000-2,000 张图像后,脚本卡在“转换”行。 (它挂起的确切图像每次都不同)。
#! /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
最佳答案
首先更详细地描述“悬挂”的含义。它会停止执行吗? convert
是否在 100% CPU 使用率下工作了一段时间?还有别的吗?
然后开始调试脚本。请添加一些调试输出并尝试使用 bash -x script.sh
运行脚本,它应该输出实际运行的所有命令。
#! /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
关于linux - ImageMagick 转换循环挂起,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5650820/