←back to thread

2039 points Gadiguibou | 1 comments | | HN request time: 0.321s | source
Show context
strogonoff ◴[] No.36495008[source]
You can use sips together with iconutil to generate a complete .icns file for your app from a single 1024 by 1024 PNG without any third party software:

    mkdir MyIcon.iconset
    cp Icon1024.png MyIcon.iconset/icon_512x512@2x.png
    sips -z 16 16     Icon1024.png --out MyIcon.iconset/icon_16x16.png
    sips -z 32 32     Icon1024.png --out MyIcon.iconset/icon_16x16@2x.png
    sips -z 32 32     Icon1024.png --out MyIcon.iconset/icon_32x32.png
    sips -z 64 64     Icon1024.png --out MyIcon.iconset/icon_32x32@2x.png
    sips -z 128 128   Icon1024.png --out MyIcon.iconset/icon_128x128.png
    sips -z 256 256   Icon1024.png --out MyIcon.iconset/icon_128x128@2x.png
    sips -z 256 256   Icon1024.png --out MyIcon.iconset/icon_256x256.png
    sips -z 512 512   Icon1024.png --out MyIcon.iconset/icon_256x256@2x.png
    sips -z 512 512   Icon1024.png --out MyIcon.iconset/icon_512x512.png
    iconutil -c icns MyIcon.iconset
As a bonus, generate .ico with ffmpeg:

    ffmpeg -i MyIcon.iconset/icon_256x256.png icon.ico
Incidentally, does anyone know enough about the way sips scales PNGs to confirm that it makes sense to create the 16px version straight from 1024px, as opposed to basing it off 32px (and all the way up)? I.e., is it better to downscale in fewer steps (as currently) or in smaller steps?
replies(4): >>36495648 #>>36500938 #>>36502128 #>>36505339 #
photonerd ◴[] No.36495648[source]
additional bonus, you can input an SVG at the start if you use qlmanage first instead of the cp command:

qlmanage -t -s 1024x1024 -o MyIcon.iconset/Icon1024.png icon.svg

replies(1): >>36495804 #
strogonoff ◴[] No.36495804[source]
Note of caution: if qlmanage uses QuickLook SVG rendering, YMMV. I recently had to deal with SVGs that render broken in Finder but correctly in, say, Affinity or Adobe tools.

Rasterization feels sufficiently finicky that I personally would consider it part of designer’s workflow rather than automated conversion pipeline; but then some would say the same about raster versions at different sizes, so in the end it depends on what you can and want spend resources at.

If it does work for you, though, you could generate every size from SVG directly and skip sips altogether (but you should check both methods to see which gives you a better quality icon, at small sizes single pixels can matter and so it would depend on how qlmanage handles rasterization to different sizes).

replies(1): >>36496413 #
1. photonerd ◴[] No.36496413[source]
That’s fair. I will say, I’ve found that svgs that only rendered “right” in Adobe/Affinity to be broken most other places too.

May be a version thing, may be some extended stuff that more common parsers do not support, not sure.