Instantly share code, notes, and snippets.

Embed
What would you like to do?
generate mutant emoji CSS and HTML
<?php
function rglob ($pattern, $flags = 0, $traversePostOrder = false) {
// Keep away the hassles of the rest if we don't use the wildcard anyway
if (strpos($pattern, '/**/') === false) {
return glob($pattern, $flags);
}
$patternParts = explode('/**/', $pattern);
// Get sub dirs
$dirs = glob(array_shift($patternParts) . '/*', GLOB_ONLYDIR | GLOB_NOSORT);
// Get files for current dir
$files = glob($pattern, $flags);
foreach ($dirs as $dir) {
$subDirContent = rglob($dir . '/**/' . implode('/**/', $patternParts), $flags, $traversePostOrder);
if (!$traversePostOrder) {
$files = array_merge($files, $subDirContent);
} else {
$files = array_merge($subDirContent, $files);
}
}
return $files;
};
$dir = 'emoji';
$out = fopen('mutant.css', 'w');
$out_html = fopen('mutant.html', 'w');
fwrite($out, '.mt{height:1.5em;width:1.5em;background-position:center;background-repeat:no-repeat;');
fwrite($out, 'background-size:contain;display:inline-block;vertical-align:middle}');
fwrite($out_html, '<!doctype html><html><head><link href="mutant.css" rel="stylesheet"></head><body><ul class="emoji">');
foreach (rglob($dir.'/**/*.png') as $filename) {
$shortcode = pathinfo($filename)['filename'];
echo $shortcode.PHP_EOL;
fwrite($out, '.mt_'.$shortcode.'{background-image:url('.$filename.')}');
fwrite($out_html, '<li><span class="mt mt_'.$shortcode.'"></span>mt_'.$shortcode.'</li>');
}
fclose($out);
fwrite($out_html, '</ul></body></html>');
fclose($out_html);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment