[英]Batch convert Shell Script for ImageMagick
I want to batch convert / loop through all images within the folder "/input" and then optimise all the images and finally output them in the folder "/output". 我想批量转换/遍历文件夹“ / input”内的所有图像,然后优化所有图像,最后将它们输出到文件夹“ / output”中。
How can I do something similar to this: 我该如何做类似的事情:
convert /Users/james/Desktop/image-magick/santorini.jpg -sampling-factor 4:2:0 -strip -quality 75 -resize 700x466! -interlace JPEG -colorspace RGB -background white -flatten /Users/james/Desktop/image-magick/final/santorini-opt.jpg
^ Currently with the above script, I have to run manually for every image, one at a time! ^目前,使用上述脚本时,我必须为每个图像手动运行一次,一次!
How can I do something similar using shell script to do it all for me in bulk? 如何使用Shell脚本为我批量完成所有操作?
You should use mogrify
command instead of convert
. 您应该使用
mogrify
命令而不是convert
。 Use -path
option to create output images in a specific directory. 使用
-path
选项可在特定目录中创建输出图像。 If you don't, your original images will be overwritten. 否则,原始图像将被覆盖。
mogrify -sampling-factor 4:2:0 -strip -quality 75 -resize 700x466! -interlace JPEG -colorspace RGB -background white -flatten -path /Users/james/Desktop/image-magick/final/ /Users/james/Desktop/image-magick/*.jpg
The previous answer is almost correct. 先前的答案几乎是正确的。 Also use -strip first before any other settings or they will be lost.
也请先使用-strip,然后再进行其他任何设置,否则它们将丢失。 Also current versions of ImageMagick use -colorspace sRGB unless you want the darker linear RGB colorspace.
除非您想要更深的线性RGB颜色空间,否则ImageMagick的当前版本也使用-colorspace sRGB。 The following has proper ImageMagick syntax to strip, convert to sRGB, resize and then set all the jpg output settings.
以下内容具有适当的ImageMagick语法,可进行剥离,转换为sRGB,调整大小,然后设置所有jpg输出设置。
cd path2/inputdirectory
mogrify -strip -colorspace sRGB -resize "700x466!" -background white -flatten -interlace JPEG -sampling-factor 4:2:0 -quality 75 -path /Users/james/Desktop/image-magick/final/ *.jpg
Note that JPG does not support transparency, so I am not sure why you have -background white -flatten in the command. 请注意,JPG不支持透明度,因此我不确定为什么在命令中使用-background white -flatten。 That would be appropriate if your input were png (ie *.png or just * to handle all formats)
如果您输入的是png(即* .png或仅*以处理所有格式),那将是适当的
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.