Lossless jpeg batch crop

好久不见. 提交于 2019-12-08 04:18:41

问题


I need to crop a bunch of jpegs by 20 pixels on the right side losslessly. Do you know about any software that can do that? 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. Any ideas?


回答1:


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

Points to note:

  • Adjust the path to the correct value
  • Do you need *.jpeg?
  • identify is an ImageMagick command
  • awk will grab the pixel dimensions from identify to use as a parameter (with the width reduced by 20px) for jpegtran 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.



回答2:


BatchCrop can do this. It supports both Windows and Mac.

www.batchcrop.com



来源:https://stackoverflow.com/questions/19848330/lossless-jpeg-batch-crop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!