Skip to content

Instantly share code, notes, and snippets.

@jpwain
Created May 4, 2017 17:54
Show Gist options
  • Save jpwain/c1fb80d31e028ddb6984c8b406fa3b52 to your computer and use it in GitHub Desktop.
Save jpwain/c1fb80d31e028ddb6984c8b406fa3b52 to your computer and use it in GitHub Desktop.
asset size comparison
#!/bin/bash
ARGC=$#
# if no directory specified, use current
if [ $ARGC -eq 0 ]
then
BASEDIR=${PWD}
else
BASEDIR=${1}
fi
cd ${BASEDIR}
# list one file per line excluding those that contains '@2x' in the filename
# use the output to feed the 'while' loop
ls -1 | grep -v \@2x | while read FILENAME
do
BASENAME="${FILENAME%.*}"
EXT="${FILENAME##*.}"
FILENAME2X="${BASENAME}@2x.${EXT}"
# if no corresponding @2x file exists, skip it
if [ ! -f "${FILENAME2X}" ]
then
continue
fi
# get the dimensions for both 1x and 2x images
W1=`sips -g pixelWidth "${FILENAME}" | grep pixelWidth | awk '{ print $2 }'`
H1=`sips -g pixelHeight "${FILENAME}" | grep pixelHeight | awk '{ print $2 }'`
W2=`sips -g pixelWidth "${FILENAME2X}" | grep pixelWidth | awk '{ print $2 }'`
H2=`sips -g pixelHeight "${FILENAME2X}" | grep pixelHeight | awk '{ print $2 }'`
# calculate double the sizes of 1x
DW1=`expr ${W1} \* 2`
DH1=`expr ${H1} \* 2`
# check for inequality between the calculated values and the actual 2x image sizes
if [ ${DW1} -ne ${W2} -o ${DH1} -ne ${H2} ]
then
echo "${FILENAME} / ${FILENAME2X}"
if [ ${DW1} -ne ${W2} ]
then
echo "width: ${W1}/${W2}"
fi
if [ ${DH1} -ne ${H2} ]
then
echo "height: ${H1}/${H2}"
fi
echo
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment