linux - ImageMagick 转换循环挂起

标签 linux bash

我正在运行一个脚本,用于调整文件夹及其子目录中所有图像的大小(如果尺寸为特定大小)。在处理了大约 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/

相关文章:

linux - Chromedriver 手动工作,但从 Jenkins Slave 运行时失败

regex - 在 bash 脚本中查找文件夹名称的一部分

bash - expr 显示表达式而不是求解它

bash - 使用 `at` 进行作业调度。 "EOF: not found"

linux - "continuous"带八进制转储的输出

C 字符串字符串比较总是导致 false

c++ - 以编程方式确定我正在运行的发行版

python - 用于在文件夹中查找文件的 Bash 脚本

linux - CGI 脚本未通过 .sh 脚本执行或调用

bash - 如何在Dockerfile中正确格式化嵌套的bash命令?