Last active
January 2, 2023 23:33
-
-
Save hagure/b787a5dfbc630ade55c9a9c64b9955bd to your computer and use it in GitHub Desktop.
[Trim Images with ImageMagick] Trim extra space around images with imagemagick. Takes in an image.ext as input, & outputs image-trimmed.ext as output. See example here: https://twitter.com/hagure/status/1610056235826696192 #imagemagick #bash #shell
This file contains 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
#!/bin/bash | |
# REQUIRES [IMAGEMAGICK](http://imagemagick.org) | |
# brew install imagemagick | |
# Get the path to the file | |
thefilepath=$(dirname "$1") | |
# Get the file's name | |
thefilename=$(basename "$1") | |
# Get the file's base name (may fail for images with multiple extensions) | |
thefilebasename=$(echo $thefilename | rev | cut -f 2- -d '.' | rev) | |
# Get the file's extension | |
thefileext=${thefilename##*.} | |
# higher fuzz = more cropping | |
convert "$1" -fuzz 10% -trim +repage "$thefilepath/$thefilebasename-trimmed.$thefileext" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment