When submitting an app to the iOS App Store, Apple requires you to provide custom app icons for all kind of ever changing device classes. I wrote a small script to generate them all a single SVG file.

#!/usr/bin/env php
<?php

$INK = "/Applications/Inkscape.app/Contents/Resources/bin/inkscape";

if (count($argv) != 3) {
  die ("Usage: iconize icon.svg AppIcon.appiconset/Contents.json\n");
}

$IN = realpath($argv[1]);
$PREFIX = basename($IN, '.svg');
$JSON = $argv[2];
$OUT = dirname(realpath($JSON));

$contents = json_decode(file_get_contents($JSON));

foreach ($contents->images as $image) {
  $size = (float) explode('x', $image->size)[0];
  $scale = (float) explode('x', $image->scale)[0];
  $id = $size;
  if ($scale != 1) $id .= "@{$scale}x";
  $filename = "{$PREFIX}-{$id}.png";
  $dim = $size * $scale;
  $image->filename = $filename;
  
  $out_esc = escapeshellarg("{$OUT}/{$filename}");
  $in_esc = escapeshellarg($IN);
  $cmd = "$INK -z -C -b white -e $out_esc -f $in_esc -w $dim -h $dim";
  echo "> $cmd\n";
  exec($cmd);
}

$out = json_encode($contents, JSON_PRETTY_PRINT) . "\n";
file_put_contents($JSON, $out);

echo "done.\n";

The first argument is the source icon, the second argument is the Contents.json inside an .appiconset. All existing images will be replaced.

The source icon should be square. I tend to use a page size of 1024 x 1024 px. Fill the whole square; the round corners are applied on the device.

$INK needs to point to the Inkscape binary.

The command line arguments are documented here. The background is explicitly set to white, because otherwise the App Store will complain about transparency (even if the whole page is opaque).

You’re welcome!