Linux上的无损jpeg批处理作物 [英] Lossless jpeg batch crop on Linux
本文介绍了Linux上的无损jpeg批处理作物的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Linux上,我需要在右侧无损地裁剪许多jpeg
格式的图像20像素.
I need to crop a number of images in jpeg
format by 20 pixels on the right side losslessly on Linux.
我检查了jpegtran
,但是在裁切之前它需要文件大小(以像素为单位),而且我不知道如何用该文件构建批处理文件.
I checked jpegtran
, but it needs the file size in pixels before cropping, and I don't know how to build a batch file with that.
如何以编程方式从图像的右侧无损地裁剪20个像素?
How can I losslessly crop 20 pixels from the right side of images programmatically?
推荐答案
我的shell脚本有点生锈,因此在尝试使用此脚本之前,请先备份图像.
My shell scripting is a little rusty so please make a backup of your images before trying this script.
#!/bin/bash
FILES=/path/to/*.jpg
for f in $FILES
do
identify $f | awk '{ split($3, f, "x"); f[1] -= 20; cl = sprintf("jpegtran -crop %dx%d+0+0 %s > new_%s", f[1], f[2], $1, $1); system(cl); }'
done
注意事项:
- 将路径调整为正确的值
- 您需要* .jpeg吗?
-
identify
是ImageMagick命令 -
awk
将从identify
抓取像素尺寸,以用作jpegtran
裁剪图像的参数(宽度减小20px) - 新图像另存为
new_[old_name].jpg
-
jpegtran
可能会调整裁切区域,以便可以无损执行.检查生成的图像尺寸正确且不大.
- Adjust the path to the correct value
- Do you need *.jpeg?
identify
is an ImageMagick commandawk
will grab the pixel dimensions fromidentify
to use as a parameter (with the width reduced by 20px) forjpegtran
to crop the image- The new image is saved as
new_[old_name].jpg
jpegtran
might adjust the cropping region so that it can perform losslessly. Check that the resulting images are the correct size and not slightly larger.
这篇关于Linux上的无损jpeg批处理作物的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文