Created
June 4, 2015 10:51
-
-
Save splitbrain/9ff65a2898ab3ad6ceac to your computer and use it in GitHub Desktop.
iOS image assets to Andorid DIP buckets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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