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 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.