Skip to content

Instantly share code, notes, and snippets.

@ck-on
Last active February 4, 2016 12:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ck-on/1b80c2c0e3b2ede26068 to your computer and use it in GitHub Desktop.
Save ck-on/1b80c2c0e3b2ede26068 to your computer and use it in GitHub Desktop.
Patch Emoji-One Moon Color to Silver instead of Yellow
<?php
/*
Patches Emoji-One svg moon shapes to use silver color instead of bright yellow.
Free for any kind of use, distribution or modification, no attribution required.
Possible to use same technique to create Unicode 8.0 diversity skin colors.
Re-render png from svg via: inkscape -z -w 64 -h 64 -f infile.svg -e outfile.png
version 0.0.5
*/
$path=dirname ( __FILE__ ).DIRECTORY_SEPARATOR; // edit path if running outside SVG directory
$replace=array('#f5eb35'=>'#c0c0c0','#e0cf35'=>'#b8b8b8');
$patched=0;
$br="\n";
echo (empty($argc)?'<pre>':''),'searching for SVG in ',$path,$br;
foreach (array('1f31','f09f8c9') as $base) { // handles both original and binary named files
for ($pass=0;$pass<2;$pass++) { // search uppercase and lowercase filenames
for ($i=1;$i<14;$i++) { // since not all systems support glob braces
$name=$base.dechex($i); $name=$pass?strtoupper($name):strtolower($name);
$file=$path.($name=$name.'.svg');
if (is_file($file) && is_writable($file)) {
if ($name!==basename(realpath($file))) { continue; } // case-insensitive systems
$data=file_get_contents($file);
$size=strlen($data);
$count=0;
foreach ($replace as $old=>$new) {
$data=str_replace('fill="'.$old.'"','fill="'.$new.'"',$data,$replaced);
$count+=$replaced;
}
if ($count) {
$count=file_put_contents($file,$data);
if ($count===false || $count!=$size) { echo 'Error writing: ',$name,$br; }
else { echo 'Successfully patched: ',$name,$br; $patched++; }
} else { echo 'Did not patch: ',$name,$br; }
}
}
}
} echo str_repeat('-', 50),$br,$patched,' total SVG files patched',$br;
@bas00000009
Copy link

nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment