Skip to content

Instantly share code, notes, and snippets.

@Oreolek
Created November 27, 2018 15:22
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 Oreolek/fe58789bc68bb45ac904bf3ee44aad6f to your computer and use it in GitHub Desktop.
Save Oreolek/fe58789bc68bb45ac904bf3ee44aad6f to your computer and use it in GitHub Desktop.
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