jpegcropbatch-processinglossless

Lossless jpeg batch crop on Linux


I need to crop a number of images in jpeg format by 20 pixels on the right side losslessly on Linux.

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.

How can I losslessly crop 20 pixels from the right side of images programmatically?


Solution

  • 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: