linux - imagemagick convert 命令在我的系统上似乎无法正常工作

标签 linux shell ubuntu terminal imagemagick-convert

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

~/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 的官方网站,但没有提及此问题。

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

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

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

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

最佳答案

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

$ 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

关于linux - imagemagick convert 命令在我的系统上似乎无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60975226/

相关文章:

python - SaltStack 颗粒错误

file - Ubuntu中的分布式文件系统

shell - 通过 shell 脚本基于变量主机名从 ssh 配置中获取 IdentityFile

linux - 无法获得这个简单的 sed 命令

mysql - 如何在ubuntu Linux中运行 Crystal 报表

c - 使用 syslog.h 将自定义时间戳写入 syslog

linux - 在 bash 中获取随机站点名称

python - 关于在 python 脚本中导入 psutil 的问题

java - linux用java直接输出到屏幕

windows - "Unix shell"- Windows 下的类似脚本