我在一个具有顺序名称的目录中有这么多不同的图像,1 2 3 4 ...
我想知道是否有可能在jpg
不保留宽高比的情况下将它们全部转换为大小并将它们调整为900x900。
我在第一部分中尝试过的是:
$ mogrify -format jpg -- *
但是,当我这样做时,内存使用量增加得如此之快,然后终止了进程。我尝试调整大小的是:
$ mogrify -resize 900x900 -- *
mogrify: insufficient image data in file `109.jpg' @ error/jpeg.c/ReadJPEGImage/1039.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
mogrify: no decode delegate for this image format `' @ error/constitute.c/ReadImage/501.
正如我所说的,文件名是连续数字。我也有以下内容:
$ file * | grep -Po "^\d*: *\K[^:,]*(?=,)" | sort | uniq
ASCII text
GIF image data
JPEG image data
PNG image data
那是什么问题呢?我该如何解决?
我建议使用convert
ImageMagick中的工具:
convert input.png -resize 900x900 output.jpg
该-resize
选项应该很明显,并且使用文件扩展名自动确定输出文件格式。
要在当前目录中的所有文件上运行此命令,请尝试以下操作:
for inputfile in ./* ; do
outputfile="${inputfile%.*}.jpg"
convert "$inputfile" -resize 900x900 "$outputfile" &&
[[ -e "$outputfile" && "$inputfile" != "$outputfile" ]] && rm "$inputfile"
done
这将从当前目录中获取所有文件(无论文件类型如何),并通过剥离旧扩展名并添加“ .jpg”来为每个输入文件创建各自的输出文件名。然后,它convert
如上所述使用来调整图像的大小和转换,从而创建一个新文件并保留原始文件。如果成功(&&
),请检查输出文件是否存在,以及输入文件名是否与输出文件名不同(例如,原始文件之一已经是jpg)。现在,如果满足这些条件,我们假定可以删除输入文件。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句