【发布时间】:2010-12-25 23:32:32
【问题描述】:
有没有可以处理各种格式的轻量级命令行批量图像裁剪工具(Linux 或 Windows)?
【问题讨论】:
-
关于您的系统,您还有什么想告诉我们的吗?例如,哪个操作系统?
-
Linux 或 Windows。我的小上网本上都有。
标签: image image-manipulation crop os-agnostic
有没有可以处理各种格式的轻量级命令行批量图像裁剪工具(Linux 或 Windows)?
【问题讨论】:
标签: image image-manipulation crop os-agnostic
Imagemagick 是您想要的——经过实践验证。
【讨论】:
到目前为止,我发现 nconvert 非常方便。
【讨论】:
在 Linux 中你可以使用
mogrify -crop {Width}x{Height}+{X}+{Y} +repage image.png
用于 CLI 图像处理
【讨论】:
brew install imagemagick然后看看你的新好东西...ls -lrt /usr/local/bin/
+repage 参数和裁剪运算符。
mogrify -alpha on -auto-orient *.jpg
mogrify 将覆盖图像,而convert 将写入新图像
Imagemagick 的转换对我有用(而且不仅仅是裁剪):
convert -crop +100+10 in.jpg out.jpg
从左边框裁剪 100 像素,从顶部裁剪 10 像素。
convert -crop -100+0 in.jpg out.jpg
从右侧裁剪 100 像素,依此类推。 Imagemagick 网站了解更多:
【讨论】:
convert 还提供自动裁剪/自动裁剪,通过-trim 选项。
-trim 太棒了!它会自动切掉所有的白边。
我已经扫描了一些页面,所有大约 130 页都需要裁掉页面下方的大约 1/8。
使用mogrify 对我不起作用,
a@a-NC210-NC110:/media/a/LG/AC/Learn/Math/Calculus/Workshop/clockwise/aa$ mogrify -quality 100 -crop 2592×1850+0+0 *.jpg
mogrify.im6: invalid argument for option `2592×1850+0+0': -crop @ error/mogrify.c/MogrifyImageCommand/4232.
但是convert 做到了:
a@a-NC210-NC110:~/Pictures/aa$ convert '*.jpg[2596x1825+0+0]' letter%01d.jpg
a@a-NC210-NC110:~/Pictures/aa$
我在 Inline Image Crop 部分学习了这个here。
注意我的语法:我必须将几何图形放在括号中:[]。
使用上述成功的语法,但使用 mogrify 根本不起作用,产生:
a@a-NC210-NC110:~/Pictures/aa$ mogrify '*.jpg[2596x1825+0+0]' letter%01d.jpg
mogrify.im6: unable to open image `letter%01d.jpg': No such file or directory @ error/blob.c/OpenBlob/2638.
Linux a-NC210-NC110 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:12 UTC 2014 i686 i686 i686 GNU/Linux
Lubuntu 14.04 LTS
【讨论】:
for f in final/**/*;
do
convert -crop 950x654+0+660 "$f" "${f%.jpg}".jpg
done
此脚本循环遍历所有子文件夹并裁剪 .jpg 文件。
【讨论】:
macOS 集成了sips 图像处理工具。可用的裁剪功能有:
-c, --cropToHeightWidth pixelsH pixelsW
--cropOffset offsetY offsetH
【讨论】: