Skip to content

Instantly share code, notes, and snippets.

@splitbrain
Created June 4, 2015 10:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save splitbrain/9ff65a2898ab3ad6ceac to your computer and use it in GitHub Desktop.
Save splitbrain/9ff65a2898ab3ad6ceac to your computer and use it in GitHub Desktop.
iOS image assets to Andorid DIP buckets
#!/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";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment