From 04a677a535570dae64e17b649b1fb84a03cb65f4 Mon Sep 17 00:00:00 2001 From: Guillaume BIENKOWSKI Date: Tue, 15 Oct 2013 16:04:11 +0200 Subject: [PATCH] Fix the asset optimization for good: - asset names for iPad were not named correctly - the UIMainBar's dialer was not using background images --- .../LinphoneUI/en.lproj/UIMainBar~ipad.xib | 12 ++--- ImageOptim.sh | 48 ++++++++++++++----- 2 files changed, 43 insertions(+), 17 deletions(-) diff --git a/Classes/LinphoneUI/en.lproj/UIMainBar~ipad.xib b/Classes/LinphoneUI/en.lproj/UIMainBar~ipad.xib index 3ab58826c..970a2b7dc 100644 --- a/Classes/LinphoneUI/en.lproj/UIMainBar~ipad.xib +++ b/Classes/LinphoneUI/en.lproj/UIMainBar~ipad.xib @@ -245,15 +245,15 @@ 0 NO - + NSImage dialer_over.png - + NSImage dialer_selected - + NSImage dialer_default.png @@ -589,9 +589,9 @@ 0 NO - - - + + + diff --git a/ImageOptim.sh b/ImageOptim.sh index 6e054affa..b9b442c01 100755 --- a/ImageOptim.sh +++ b/ImageOptim.sh @@ -23,29 +23,55 @@ PNGS=$(find $DIR -type f -name *.png) echo "Running PNG optimization in $DIR" +if [[ -f $DIR/optimized ]]; then + echo "Resources already optimized, exit" + exit 0 +fi + for PNG in $PNGS; do BASENAME=$(basename $PNG ".png") - PROCESS=false # put true here when the resizing is fixed + SUFFIX= + PROCESS=true - if [ -f $DIR/$BASENAME"@2x.png" ]; then + # detect images for iPad, in which case basename has to be stripped + case $BASENAME in + *~ipad) + SUFFIX="~ipad" + BASENAME=$(echo ${BASENAME} |cut -f1 -d~) + ;; + esac + + STANDARDFILE=${BASENAME}${SUFFIX}.png + RETINAFILE=${BASENAME}@2x${SUFFIX}.png + + + # skip resize if the retina version already exist, which means the asset was optimized manually + if [ -f $DIR/$BASENAME"@2x"$SUFFIX".png" ]; then echo "Don't process $BASENAME"; PROCESS=false fi - case $BASENAME in *@2x) - echo "Skip $BASENAME"; - continue + case $BASENAME in + *@2x$SUFFIX) + continue + ;; esac + # for all resources that don't have retina versions, consider the normal version as retina and resize to 50% if $PROCESS ; then - echo -n "Processing ${BASENAME} (${CONVERTFILTER})..." - mv $DIR/$BASENAME".png" $DIR/$BASENAME"@2x.png" - $CONVERT $DIR/$BASENAME"@2x.png" $CONVERTFILTER -resize "50%" $DIR/$BASENAME".png" > /dev/null + + echo -n "Processing ${STANDARDFILE} (${CONVERTFILTER})..." + + mv ${DIR}/$STANDARDFILE ${DIR}/$RETINAFILE + $CONVERT ${DIR}/$RETINAFILE $CONVERTFILTER -resize "50%" -strip ${DIR}/$STANDARDFILE > /dev/null fi echo "Optimizing ${BASENAME} and ${BASENAME}@2x ..." - $OPTIPNG -quiet $DIR/$BASENAME"@2x.png" > /dev/null - $OPTIPNG -quiet $DIR/$BASENAME".png" > /dev/null + $OPTIPNG -quiet $DIR/$RETINAFILE > /dev/null + $OPTIPNG -quiet $DIR/$STANDARDFILE > /dev/null -done \ No newline at end of file +done + +# make sure we dont over-optimize +touch $DIR/optimized \ No newline at end of file