【问题标题】:imagemagic's convert command doesnt seem to work correctly on my systemimagemagick convert 命令在我的系统上似乎无法正常工作
【发布时间】:2020-07-13 11:01:00
【问题描述】:

我试图批量降低系统上存储在该位置的某些图像的质量

~/sandboxArea/MainCam

然后我运行了以下命令

for i in $(ls ~/sandboxArea/MainCam); do convert $i -quality 30 ~/sandboxArea/converted/$i; done

上面的命令奏效了,所有文件都先缩小了大小,然后放入“~sandboxArea/converted”文件夹中

然后我再次尝试降低存储在该位置的图像质量

~/sandboxArea/SecondCam

并在进行如下所需更改后运行上述命令

for k in $(ls ~/sandboxArea/SecondCam); do convert $k -quality 30 ~/sandboxArea/convertedB/$k; done

它给了我以下错误:

convert-im6.q16: no images defined `/home/mohit/sandboxArea/convertedB/IMG_5682.JPG' @ error/convert.c/ConvertImageCommand/3258.
convert-im6.q16: unable to open image `IMG_5683.JPG': No such file or directory @ error/blob.c/OpenBlob/2701.
convert-im6.q16: no images defined `/home/mohit/sandboxArea/convertedB/IMG_5683.JPG' @ error/convert.c/ConvertImageCommand/3258.
convert-im6.q16: unable to open image `IMG_5684.JPG': No such file or directory @ error/blob.c/OpenBlob/2701.
convert-im6.q16: no images defined `/home/mohit/sandboxArea/convertedB/IMG_5684.JPG' @ error/convert.c/ConvertImageCommand/3258.
convert-im6.q16: unable to open image `IMG_5685.JPG': No such file or directory @ error/blob.c/OpenBlob/2701.
convert-im6.q16: no images defined `/home/mohit/sandboxArea/convertedB/IMG_5685.JPG' @ error/convert.c/ConvertImageCommand/3258.

我尝试了多种方法来解决这个问题,也检查了 imagemagic.org 的官方网站,但没有提到这个问题。

这是一个错误吗?由于此命令工作过一次但无法再次工作。

另外,我删除了之前保存在“converted”文件夹中的文件,以检查该命令是否会再次起作用。它也在那里失败了。因此,同一命令一次有效,另一次无效。

有人可以帮忙吗?我有大约 8000 多张图片,每张大约 7-9MB,所有这些图片都占用了大量空间。只是想在我的硬盘上节省一些空间

提前致谢。如果有人需要更多说明,请告诉我。 谢谢

【问题讨论】:

    标签: linux shell ubuntu terminal imagemagick-convert


    【解决方案1】:

    这是重现问题的更简单方法:

    $ ls ~/tmp
    foo.jpg
    
    $ convert foo.jpg bar.jpg
    convert-im6.q16: unable to open image `foo.jpg': No such file or directory @ error/blob.c/OpenBlob/2874.
    convert-im6.q16: no images defined `bar.jpg' @ error/convert.c/ConvertImageCommand/3258.
    

    问题是即使您在系统上确实有一个文件foo.jpg,但它位于不同的目录中,因此您无法在不限定名称的情况下访问它。在这种情况下,您可以改为运行:

    $ convert ~/tmp/foo.jpg c
    (success, no output)
    

    或者,您可以将当前目录更改为foo.jpg 所在的位置:

    $ cd ~/tmp
    $ convert foo.jpg ~/Downloads/bar.jpg
    (success, no output)
    

    更好的循环将遍历 glob 并正确引用以稳健地处理文件名中的空格和类似内容:

    for path in "$HOME/sandboxArea/SecondCam"/*
    do
      convert "$path" -quality 30 "$HOME/sandboxArea/convertedB/${path##*/}"
    done
    

    【讨论】:

    • 感谢您的回复。我从目录 [ ~/sandboxArea/ ] 运行命令,该目录包含其他目录“converted”“convertedB”“MainCam”“SecondCam”。恐怕我没有完全理解你的意思。还有为什么该命令以前有效,然后又失败了?如果存在 genuin 问题,那么它首先不应该工作。
    • 但是是的,您提供的解决方案有效,再次感谢。 :-)
    • 一个问题:${path##*/} 扩展成什么?
    • 如果您在~/sandboxArea 中并且想要引用文件~/sandboxArea/SecondCam/IMG_5684.JPG,那么您不能仅使用IMG_5684.JPG 来执行此操作。这只会寻找~/sandboxArea/IMG_5684.jpg。它不会在任何子目录中查找~/sandboxArea/SecondCam/IMG_5684.jpg。相反,您必须指定文件相对于当前目录的子目录,例如SecondCam/IMG_5684.JPG。您第一次可能在~/sandboxArea/SecondCam,因此不需要任何限定符即可访问IMG_5684.JPG
    • ${path##*/} 删除匹配*/ 的最长前缀,因此它实际上只获取路径中的文件名(类似于basename)。例如,如果path=/home/foo/sandboxArea/SecondCam/IMG_5684.JPG 那么${path##*/} 就是IMG_5684.JPG
    猜你喜欢
    • 1970-01-01
    • 2011-05-05
    • 1970-01-01
    • 1970-01-01
    • 2017-09-04
    • 2012-05-06
    • 2013-02-17
    • 2017-10-09
    • 2017-08-03
    相关资源
    最近更新 更多