Skip to content

Instantly share code, notes, and snippets.

@EvanLovely
Created April 26, 2014 01:29
Show Gist options
  • Save EvanLovely/11309254 to your computer and use it in GitHub Desktop.
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

Add the contents of img-sizes.sh to your ~/.bash_functions.

# 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