You can use the well known free and open-source ImageMagick
Simple example from the documentation:
convert rose: -crop 40x30+10+10 crop.gif
Where 40x30+10+10
is the geometry, basically meaning width x height + offsetX + offsetY
. All in pixels. Offset is measured from top left corner. Note that there should be no spaces between the numbers and the x
and +
signs. I'm adding spaces here for readability.
To run that for a batch of images, you could use OS completion and expansion commands depending on which system you're on. In windows command prompt for example:
for %f in (*.png) do (
convert %f -crop 40x30+10+10 cropped_%f
)
In PowerShell:
gci *.png | %{ convert -crop 40x30+10+10 $_.FullName ($_.BaseName+"_crop"+$_.Extension)}
--- edit
And in Bash:
images=$(ls -1 *.png)
for image in $images ; do
convert -crop 40x30+10+10 cropped_$image
done
If you want to recurse through all sub-directories, use:
images=$(find -type f -name '*.png')