Skip to content

Instantly share code, notes, and snippets.

@juliendargelos
Last active October 23, 2023 02:31
Show Gist options
  • Star 34 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save juliendargelos/d9a08e693dfcdab80d28dd609b717536 to your computer and use it in GitHub Desktop.
Save juliendargelos/d9a08e693dfcdab80d28dd609b717536 to your computer and use it in GitHub Desktop.
Imagemagick command that trims transparent pixels from an image.
convert input.png -trim +repage output.png
@pugson
Copy link

pugson commented Jan 27, 2021

Thanks!

Here's how to loop that over all images in a folder in case anyone stumbles upon it:

for f in *.png; do convert $f -trim +repage $f; done

@enijar
Copy link

enijar commented Jul 7, 2022

You can do this much simpler with:

mogrify *.png -trim +repage

@a-kriya
Copy link

a-kriya commented Jul 13, 2022

@enijar I had to put .png at the end to get it to work (on a Mac). Imagemagick is sensitive to order of params.

mogrify -trim +repage *.png

@j4hangir
Copy link

Pretty leet, especially mogrify 👍

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