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
}