Automatically add app version information to app icons

Source: Internet
Author: User
Tags imagemagick

from:http://merowing.info/2013/03/overlaying-application-version-on-top-of-your-icon/
Overlaying application version on top of your iconMar 7, 3 minute Read

I ' ve just returned from Nsconference #5, there were many good talks there, but my favourite one is the one about Flipboar d Development Tools/setup by Evan Doll.

Especially how they add version information on top of the icons. Unfortunately they didn ' t share it with us.

So I wrote my own.

What are we'll be overlaying?

I ' ve decided that 3 parts of information should be enough:

    • Version number
    • Branch Name
    • Short commit Hash
Version number

We can extract version number straight from our application. plist file by using Plistbuddy tool:

version="Print CFBundleVersion""${INFOPLIST_FILE}"`

PS. could extract any plist entry with this tool, just change cfbundleversion to different key (show raw keys in X Code)

Branch and Short commit hash

git command line tool offers Rev-parse command which let's you both of those variables:

commit=`git rev-parse --short HEAD`branch=`git rev-parse --abbrev-ref HEAD`
How to overlay it?

Imagemagic is my go-to tool for playing with images from command line, it offers crazy amount of functions.

Make sure to install ImageMagick and Ghostscript (fonts) First, you can use the brew to simplify process:

installinstall ghostscript

We can use the CONVERT function, by specifing caption parameter ImageMagick would layout our text on top of image, we also Setu P alignment to bottom and default height.

convert -background ‘#0008‘ -fill white -gravity center -size ${width}x40 \    caption:"${version} ${branch} ${commit}"     ${base_file} +swap -gravity south -composite  "${CONFIGURATION_BUILD_DIR}/${UNLOCALIZED_RESOURCES_FOLDER_PATH}/${target_file}"
Setting it up in Xcode project

There is few steps we need to take in order to set this up as part of the Xcode build:

    1. Rename your icon* files (where * is @2x, -568h etc.) to icon_base*, e.g. [email protected]_base.png
    2. Add run script for your target under Build phases
    3. Paste This code:
Commit= 'git rev-parse--short HEAD' Branch= 'git rev-parse--abbrev-ref HEAD' Version='/usr/libexec/plistbuddy-c"Print cfbundleversion" "${infoplist_file}" 'function processicon() {export PATH=$PATH:/ Usr/local/bin base_file=$ Base_path='     Find ${srcroot}-name$base _file 'if [[ ! -F ${Base_path} | | -Z ${ Base_path} ];  Then return ; fi target_file='                 Echo $base _file | sed "s/_base//"' Target_path="${configuration_build_dir}/${unlocalized_resources_folder_path}/${target_file} "    if [ $CONFIGURATION = "Release" ];  Then    CP ${base_file} $target _path    return    fiWidth= 'identify-format%w ${Base_path}' Convert-background '#0008 '-fill white-gravity center-size ${width}x40\Caption"${version} ${branch} ${commit}"    ${base_path}+swap-gravity South-composite${target_path}}Processicon"Icon_base.png"Processicon"[Email protected]_base.png]Processicon"Icon-72_base.png"Processicon"[Email protected]_base.png]
Conclusion

Few things about final script:

    • I ' ve added support for skipping icons that don ' t exist, no need to change script contents.
    • I ' m using sed to strip _base string from file name.
    • For release build we don ' t want to overlay our development info.
    • Xcode likes messes up path resolution, so I ' ve added usr/local/bin to it terminal lifetime.

Now run your project and you should see this:

Sample Project on GitHub

Automatically add app version information to app icons

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.