Last active
November 20, 2025 13:04
-
-
Save juliendargelos/d9a08e693dfcdab80d28dd609b717536 to your computer and use it in GitHub Desktop.
Imagemagick commands that trims transparent pixels from an image.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Trim a single "input.png" image and save to "output.png" | |
| magick input.png -trim +repage output.png | |
| # Trim a single "image.png" image and overwrite the original file (based on @enijar comment) | |
| mogrify -trim +repage image.png | |
| # Trim and overwrite all png images from the working directory (based on @enijar comment) | |
| mogrify -trim +repage *.png |
You can do this much simpler with:
mogrify *.png -trim +repage@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 *.pngPretty leet, especially mogrify 👍
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks!
Here's how to loop that over all images in a folder in case anyone stumbles upon it: