Add the contents of img-sizes.sh
to your ~/.bash_functions
.
Created
April 26, 2014 01:29
-
-
Save EvanLovely/11309254 to your computer and use it in GitHub Desktop.
Display image sizes in the command line for either a single image or a whole directory
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
# Run on an image to see it's width & height in pixels, then copy the CSS syntax for it. | |
imgsize () { | |
width=$(mdls -name kMDItemPixelWidth -raw "$1") | |
height=$(mdls -name kMDItemPixelHeight -raw "$1") | |
echo "width: "$width"px; | |
height: "$height"px;" | pbcopy | |
echo "$width"x"$height" | |
} | |
# Displays all images in a directory with image sizes. Either pass in a folder or run as-is to list the current directory | |
lsimgsizes() { | |
if [[ "$#" == 0 ]]; then | |
path="." | |
else | |
path=$1 | |
fi | |
IFS=$'\n' | |
for i in $(mdfind -onlyin "$path" "kind:image"); do | |
echo -n $(basename "$i") | |
width=$(mdls -name kMDItemPixelWidth -raw "$i") | |
height=$(mdls -name kMDItemPixelHeight -raw "$i") | |
echo " - $width"x"$height" | |
done | |
unset IFS | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment