Created
March 31, 2020 15:17
-
-
Save luigimannoni/bb76046fa5dde7cf80508db2529b8f9e to your computer and use it in GitHub Desktop.
Imagemagick Mogrify/Resize image to nearest power of two
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 | |
# Or add to ~/bash_aliases | |
magickpow2 () { | |
echo Running imagemagick nearest pow with extension "$1" | |
for file in $(find . -name "$1") | |
do echo processing "$file" | |
local powwidth=$(identify -format "%[fx:2^(floor(log(w)/log(2)))]" $file) | |
if [ -z $powwidth ] | |
then | |
echo "$file" cannot be read | |
else | |
local powheight=$(identify -format "%[fx:2^(floor(log(h)/log(2)))]" $file) | |
mogrify -resize "$powwidth"x"$powheight" $file | |
echo $file resized to "$powwidth"x"$powheight" | |
fi | |
done | |
} | |
# Usage: | |
magickpow2 '*.png' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment