Skip to content

Instantly share code, notes, and snippets.

@comstock
Last active November 29, 2023 11:28
Show Gist options
  • Select an option

  • Save comstock/48923cb5af55a0114e2faba9980e4c49 to your computer and use it in GitHub Desktop.

Select an option

Save comstock/48923cb5af55a0114e2faba9980e4c49 to your computer and use it in GitHub Desktop.
Convert all the JP2 images in a directory to JPEGs using GraphicsMagick's Mogrify; crop image edges with Imagemagick's Convert

Format change & resize

  • mogrify -format jpg -quality 85 *.jp2
  • mogrify -format jpg -quality 85 -resize 2048x *.jp2 # specifying pixel-width limit.

Rotate

  • mogrify rotateMe.jpg -rotate 90
  • convert input.jpg -rotate 90 output.jpg

Trim one side of an image w/chop

  • trim edge of image by 200 pixels
    • left side: convert mushroom.jpg -gravity West -chop 200x0 Lcrop.jpg.jpg
    • right side: convert mushroom.jpg -gravity East -chop 200x0 Rcrop.jpg.jpg
    • top side: convert mushroom.jpg -gravity North -chop 0x200 Tcrop.jpg.jpg
    • bottom side: convert mushroom.jpg -gravity South -chop 0x300 Bcrop.jpg.jpg

Crop all sides of an image w/shave

  • trim 200 pixels from left and right, and 500 pixels from top and bottom: convert unshaved.jpg -shave 200x500 shaved.jpg

Enlarge a 600x600 pixel image by 25 pixels

  • white border: convert 600_square.jpg -background white -gravity center -extent 625x625 625_square_w.jpg

  • transparent border: convert 600_square.jpg -background none -gravity center -extent 625x625 625_square_tr.jpg


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment