Skip to content

Instantly share code, notes, and snippets.

@Oreolek Oreolek/generate.php
Created Nov 27, 2018

What would you like to do?
generate mutant emoji CSS and HTML
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>');
fwrite($out_html, '</ul></body></html>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.