Skip to content

Instantly share code, notes, and snippets.

@febeling
Forked from ahmed-musallam/generate-icns.sh
Last active January 13, 2024 13:01
Show Gist options
  • Select an option

  • Save febeling/d2131a91a09d9f313d03796c8a7470ae to your computer and use it in GitHub Desktop.

Select an option

Save febeling/d2131a91a09d9f313d03796c8a7470ae to your computer and use it in GitHub Desktop.

Revisions

  1. febeling revised this gist Jan 13, 2024. 1 changed file with 20 additions and 14 deletions.
    34 changes: 20 additions & 14 deletions generate-icns.sh
    Original file line number Diff line number Diff line change
    @@ -1,16 +1,21 @@
    #!/bin/bash
    # Required deps:
    # imagemagick: https://imagemagick.org/script/download.php
    # iconutil: https://developer.apple.com/library/archive/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Optimizing/Optimizing.html

    # name of your master icon, must be at least 512X512
    PNG_MASTER="icon-large.png"
    # name of your master icon, should be 1024x1024 or .svg
    if [ -z "$PNG_MASTER" ]; then
    # If not set, assign a default value
    PNG_MASTER="icon-large.png"
    fi

    ICONSET_FOLDER="AppIcon.iconset"
    sizes=(
    16x16
    32x32
    128x128
    256x256
    512x512
    16
    32
    128
    256
    512
    )

    # Generate renditions at the sizes in "sizes" above, put all in ICONSET_FOLDER
    @@ -19,12 +24,13 @@ for size in "${sizes[@]}"; do
    icon="icon_${size}.png"
    ICON_FILES="$ICON_FILES $ICONSET_FOLDER/$icon"
    echo Generating $ICONSET_FOLDER/$icon
    convert $PNG_MASTER -quality 100 -resize $size $ICONSET_FOLDER/$icon
    icon="icon_${size}@2x.png"
    convert $PNG_MASTER -quality 100 -resize ${size}x${size} $ICONSET_FOLDER/$icon

    icon="icon_${size}x${size}@2x.png"
    ICON_FILES="$ICON_FILES $ICONSET_FOLDER/$icon"
    echo Generating $ICONSET_FOLDER/$icon
    convert $PNG_MASTER -quality 100 -resize $size $ICONSET_FOLDER/$icon
    hires=$((size * 2))
    convert $PNG_MASTER -quality 100 -resize ${hires}x${hires} $ICONSET_FOLDER/$icon
    done

    # generate icon.icns for mac app (this only works on mac)
    @@ -35,11 +41,11 @@ iconutil -c icns $ICONSET_FOLDER -o icon.icns
    ICON_FILES=""
    for size in "${sizes[@]}"; do
    ICON_FILES="$ICON_FILES $ICONSET_FOLDER/icon_${size}.png"
    ICON_FILES="$ICON_FILES $ICONSET_FOLDER/icon_${size}@2x.png"
    ICON_FILES="$ICON_FILES $ICONSET_FOLDER/icon_${size}x${size}@2x.png"
    done
    echo Generating icon.ico
    convert $ICON_FILES icon.ico
    convert $ICON_FILES icon.ico

    # remove generated renditions
    echo removing $ICONSET_FOLDER folder
    rm -rf $ICONSET_FOLDER
    rm -rf $ICONSET_FOLDER
  2. @ahmed-musallam ahmed-musallam created this gist Feb 24, 2020.
    45 changes: 45 additions & 0 deletions generate-icns.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    # Required deps:
    # imagemagick: https://imagemagick.org/script/download.php

    # name of your master icon, must be at least 512X512
    PNG_MASTER="icon-large.png"

    ICONSET_FOLDER="AppIcon.iconset"
    sizes=(
    16x16
    32x32
    128x128
    256x256
    512x512
    )

    # Generate renditions at the sizes in "sizes" above, put all in ICONSET_FOLDER
    mkdir -p $ICONSET_FOLDER
    for size in "${sizes[@]}"; do
    icon="icon_${size}.png"
    ICON_FILES="$ICON_FILES $ICONSET_FOLDER/$icon"
    echo Generating $ICONSET_FOLDER/$icon
    convert $PNG_MASTER -quality 100 -resize $size $ICONSET_FOLDER/$icon

    icon="icon_${size}@2x.png"
    ICON_FILES="$ICON_FILES $ICONSET_FOLDER/$icon"
    echo Generating $ICONSET_FOLDER/$icon
    convert $PNG_MASTER -quality 100 -resize $size $ICONSET_FOLDER/$icon
    done

    # generate icon.icns for mac app (this only works on mac)
    echo Generating icon.icns
    iconutil -c icns $ICONSET_FOLDER -o icon.icns

    # Generate .ico file for windows
    ICON_FILES=""
    for size in "${sizes[@]}"; do
    ICON_FILES="$ICON_FILES $ICONSET_FOLDER/icon_${size}.png"
    ICON_FILES="$ICON_FILES $ICONSET_FOLDER/icon_${size}@2x.png"
    done
    echo Generating icon.ico
    convert $ICON_FILES icon.ico

    # remove generated renditions
    echo removing $ICONSET_FOLDER folder
    rm -rf $ICONSET_FOLDER