How to manually create icns files using iconutil?

前端 未结 18 1912
无人共我
无人共我 2020-11-29 15:08

When I\'m validating my app I get this error:

the application bundle does not contain an icon in ICNS format, containing both a 512x512

相关标签:
18条回答
  • 2020-11-29 15:26

    Here's a function mostly based off Henry's example (could be useful in ~/.bash_profile):

    mkicns() {
        if [[ -z "$*" ]] || [[ "${*##*.}" != "png" ]]; then
            echo "Input file invalid"
        else
            filename="${1%.*}"
            mkdir "$filename".iconset
            for i in 16 32 128 256 ; do
                n=$(( i * 2 ))
                sips -z $i $i "$1" --out "$filename".iconset/icon_${i}x${i}.png
                sips -z $n $n "$1" --out "$filename".iconset/icon_${i}x${i}@2x.png
                [[ $n -eq 512 ]] && \
                sips -z $n $n "$1" --out "$filename".iconset/icon_${n}x${n}.png
                (( i++ ))
            done
            cp "$1" "$filename".iconset/icon_512x512@2x.png
            iconutil -c icns "$filename".iconset
            rm -r "$filename".iconset
        fi
    }
    

    Usage:

    $ mkicns "filename.png"  # double-quote if spaces exist in filename
    

    Creates 10 sizes from 16x16 to 512x512@2x; accepts input images in .png format only.

    0 讨论(0)
  • 2020-11-29 15:32

    There are 2 tasks:
    - create 10 correct icns files
    - get your Xcode project to use them correctly

    As I had hour long problems with both of these tasks, and also do not like when I don't 'see' what is going on, here a path for the cautious ones:

    Create 10 correct icns files:
    I used the script above from Henry: It still works for HighSierra and Xcode 9.2, including the 'c' command.
    The icns file I got, appeared as only one icon size in Finder/Quicklook and in Preview showed only 8 of 10 sizes.
    So I used terminal, went with cd to my folder and used the command: iconutil -c iconset (icns filename) on the just created icns file to revert the icns file back to an iconset folder, and - lo & behold - I could see my newly created 10 icon files. Using Quick look on the iconset folder (and using full screen mode to be able to zoom through them with the slider), I could check that all sizes are actually looking very well.

    As an aside: they looked better than my resizing attempts with PSE, most likely because I did not take the time to play with all the resizing options in PSE. If you do use PSE, make sure your png files are saved without colour profile. Also, confessing my ignorance, for me a 256x256@2 file is the same as a 512x512 file - both in 72dpi. Trying to follow the 144 dpi comments above did not work for me.

    Get your Xcode project to use them correctly:
    First I deleted all my fruitless attempts within Xcode and committed a clean version to the git repository (what would have been clever, would have been to commit a clean version first - before I frantically started the icon addition odyssee).
    I also made sure that in the info.plist file there is no pointer linked to the 'icon file' entry and that in my General project settings I had chosen AppIcon for App Icons.
    Then I added an assets.asset catalog and within the assets catalog a new 'AppIcons and Launch Images' AppIcon Folder for OS.
    Then I copied (drag and drop with option pressed) from the iconset folder each png picture file into the respective AppIcon Spaceholder. So again, I could see what is happening. Xcode did convert that into icns files, or maybe - as my iconset folder derived from an icns folder - the file formats were accepted.

    Then archive and validate and there will be no errors upon uploading or validating.

    0 讨论(0)
  • 2020-11-29 15:34

    These commands (entered in Terminal) worked for me to convert an old icns file to the new format:

    cd Folder_With_Icns_File
    iconutil -c iconset Your_Icon_Name.icns 
    rm Your_Icon_Name.icns 
    iconutil -c icns Your_Icon_Name.iconset
    rm -R Your_Icon_Name.iconset
    

    Update

    The -c parameter to iconutil is no longer supported. Use --convert instead:

    cd Folder_With_Icns_File
    iconutil --convert iconset Your_Icon_Name.icns 
    rm Your_Icon_Name.icns 
    iconutil --convert icns Your_Icon_Name.iconset
    rm -R Your_Icon_Name.iconset
    
    0 讨论(0)
  • 2020-11-29 15:35

    Same as @Henry (comment above) but takes as argument the PNG filename and outputs the ICNS with the same name.

    NOTE : The PNG file name is only expected to have 1 point to separate extension, i.e. xpto.png .

    So, save the code below to a filed called "CreateICNS.src" in the folder where your png file is.

    CODE :

    IFS='.' read -ra ADDR <<< "$1"
    ICONSET=${ADDR[0]}.iconset
    mkdir $ICONSET
    sips -z 16 16     $1 --out $ICONSET/icon_16x16.png
    sips -z 32 32     $1 --out $ICONSET/icon_16x16@2x.png
    sips -z 32 32     $1 --out $ICONSET/icon_32x32.png
    sips -z 64 64     $1 --out $ICONSET/icon_32x32@2x.png
    sips -z 128 128   $1 --out $ICONSET/icon_128x128.png
    sips -z 256 256   $1 --out $ICONSET/icon_128x128@2x.png
    sips -z 256 256   $1 --out $ICONSET/icon_256x256.png
    sips -z 512 512   $1 --out $ICONSET/icon_256x256@2x.png
    sips -z 512 512   $1 --out $ICONSET/icon_512x512.png
    cp $1 $ICONSET/icon_512x512@2x.png
    iconutil -c icns $ICONSET
    rm -R $ICONSET
    

    HOW TO USE :

    Then in the terminal, "cd" to the same folder and type :

    source CreateICNS.src {PNG filename}
    

    where {PNG filename} is the name of your PNG file, i.e. xpto.png .

    If your file would be named abc.png you would use :

    source CreateICNS.src abc.png
    
    0 讨论(0)
  • 2020-11-29 15:38

    Checkout the following instructions (link):

    Use iconutil to Create an icns File Manually

    The iconutil command-line tool converts iconset folders to deployment-ready, high-resolution icns files. (You can find complete documentation for this tool by entering man iconutil in Terminal.) Using this tool also compresses the resulting icns file, so there is no need for you to perform additional compression.

    To convert a set of icons to an icns file

    Enter this command into the Terminal window:

    iconutil -c icns <iconset filename>

    where <iconset filename> is the path to the folder containing the set of icons you want to convert to icns. The output is written to the same location as the iconset file, unless you specify an output file as shown:

    iconutil -c icns -o <icon filename> <iconset filename>

    In other words, you need to replace <iconset filename> by the path:

    /Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset
    

    Since the path contains spaces, you need to use double quotes, for example:

    iconutil -c icns "/Users/myname/SDK Mac Apps/MyApp/grafica/icon.iconset"
    

    This command should work properly.

    0 讨论(0)
  • 2020-11-29 15:38

    Apple's older Icon Composer version 2.2 works just fine, you just open the .ICNS in it, press the 1024x1024 button and add your image.

    0 讨论(0)
提交回复
热议问题