Skip to content

Instantly share code, notes, and snippets.

@splitbrain
Created June 4, 2015 10:51
Show Gist options
  • Select an option

  • Save splitbrain/9ff65a2898ab3ad6ceac to your computer and use it in GitHub Desktop.

Select an option

Save splitbrain/9ff65a2898ab3ad6ceac to your computer and use it in GitHub Desktop.

Revisions

  1. splitbrain created this gist Jun 4, 2015.
    45 changes: 45 additions & 0 deletions ios2and.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,45 @@
    #!/usr/bin/php
    <?php
    /**
    * Very simple script to convert iOS xcode imageset directories to DIP buckets
    * for Android development
    */

    if(!isset($argv[2])) {
    die("Usage: ios2and.php <ios image asset folder> <android res folder>\n");
    }

    $ios = $argv[1];
    $and = $argv[2];

    foreach(glob("$ios/*.imageset/Contents.json") as $jsonfile) {
    $setdir = dirname($jsonfile);
    $setname = basename($setdir, '.imageset');
    $setname = strtolower(preg_replace('/([a-z])([A-Z])/', '$1_$2', $setname));

    $json = json_decode(file_get_contents($jsonfile), true);
    foreach($json['images'] as $img) {

    switch(strtolower($img['scale'])) {
    case '1x':
    $dip = 'mdpi';
    break;
    case '2x':
    $dip = 'xhdpi';
    break;
    case '3x':
    $dip = 'xxhdpi';
    break;
    default:
    continue;
    }

    if(!$img['filename']) continue;

    $from = "$setdir/".$img['filename'];
    $to = "$and/drawable-$dip/$setname.png"; #FIXME handle extensions
    @mkdir(dirname($to), 0777, true);
    copy($from, $to);
    echo "$from -> $to\n";
    }
    }