Command line batch image cropping tool

ImageImage ManipulationCropOs Agnostic

Image Problem Overview


is there any lightweight command line batch image cropping tool(Linux or Windows) which can handle a variety of the formats ?

Image Solutions


Solution 1 - Image

In Linux you can use

mogrify -crop {Width}x{Height}+{X}+{Y} +repage image.png

for CLI image manipulation

Solution 2 - Image

Imagemagick's convert does the trick for me (and much more than cropping):

convert -crop +100+10 in.jpg out.jpg

crops 100 pixels off the left border, 10 pixels from the top.

convert -crop -100+0 in.jpg out.jpg

crops 100 pixels off the right, and so on. The Imagemagick website knows more:

http://www.imagemagick.org/Usage/crop/#crop

Solution 3 - Image

Imagemagick is what you want -- tried and true.

Solution 4 - Image

I found nconvert pretty handy so far.

Solution 5 - Image

for f in final/**/*;
do
   convert -crop 950x654+0+660 "$f" "${f%.jpg}".jpg
done

This script loops through all the sub-folders and crops the .jpg files.

Solution 6 - Image

macOS has sips image processing tool integrated. Cropping functions available are:

    -c, --cropToHeightWidth pixelsH pixelsW 
        --cropOffset offsetY offsetH 

Solution 7 - Image

I have scanned some pages and all ~130 pages needs the lower ~1/8 of the page cut off.

Using mogrify didn't work for me,

a@a-NC210-NC110:/media/a/LG/AC/Learn/Math/Calculus/Workshop/clockwise/aa$ mogrify -quality 100 -crop 2592×1850+0+0 *.jpg  
mogrify.im6: invalid argument for option `2592×1850+0+0': -crop @ error/mogrify.c/MogrifyImageCommand/4232.

However convert did:

a@a-NC210-NC110:~/Pictures/aa$ convert '*.jpg[2596x1825+0+0]' letter%01d.jpg  
a@a-NC210-NC110:~/Pictures/aa$

I learnt this here under the Inline Image Crop section.

Notice my syntax: I had to put my geometry in brackets: [].

Using the successful syntax above but with mogrify simply didn't work, producing:

a@a-NC210-NC110:~/Pictures/aa$ mogrify '*.jpg[2596x1825+0+0]' letter%01d.jpg
mogrify.im6: unable to open image `letter%01d.jpg': No such file or directory @ error/blob.c/OpenBlob/2638.

Linux a-NC210-NC110 3.13.0-32-generic #57-Ubuntu SMP Tue Jul 15 03:51:12 UTC 2014 i686 i686 i686 GNU/Linux
Lubuntu 14.04 LTS

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionicemanView Question on Stackoverflow
Solution 1 - ImageRalphView Answer on Stackoverflow
Solution 2 - ImageKlausView Answer on Stackoverflow
Solution 3 - Imageaxel_cView Answer on Stackoverflow
Solution 4 - ImageJoeyView Answer on Stackoverflow
Solution 5 - ImageJeffry AntoView Answer on Stackoverflow
Solution 6 - ImagewobmeneView Answer on Stackoverflow
Solution 7 - ImageMr. ComlyView Answer on Stackoverflow