diff --git a/php/generate-preview.php b/php/generate-preview.php new file mode 100644 index 0000000..88f17f7 --- /dev/null +++ b/php/generate-preview.php @@ -0,0 +1,49 @@ +setBackgroundColor(new ImagickPixel('#ffffff')); + $image->readImageBlob(file_get_contents($icon_path)); + $image->setImageFormat("png24"); + $image->setImageInterpolateMethod(Imagick::INTERPOLATE_INTEGER); + $image->resizeImage(180, 180, Imagick::FILTER_POINT, 1); + $image->borderImage('#ffffff', 510, 225); + $image->writeImage($preview_path); +} + +$current_icon = false; +if (isset($argv[1])) { + $current_icon = $argv[1]; +} elseif (isset($_GET['icon'])) { + $current_icon = $_GET['icon']; +} + +$icon_dir = __DIR__."/icons"; +$preview_dir = __DIR__."/preview"; + +if ($current_icon) { + $icon_path = "$icon_dir/$current_icon.svg"; + $preview_path = "$preview_dir/$current_icon.png"; + generate_preview($icon_path, $preview_path); +} else { + // no icon specified, generate all + + $icon_json = json_decode(file_get_contents(__DIR__ . "/assets/icons.json"), true); + + foreach ($icon_json as $filename => $tags) { + $icon_name = str_replace(".svg", "", $filename); + $icon_path = "$icon_dir/$filename"; + $preview_path = "$preview_dir/$icon_name.png"; + + if (is_file($preview_path) && filemtime($preview_path) > filemtime($icon_path)) { + continue; + } + + generate_preview($icon_path, $preview_path); + } + + $file = fopen(__DIR__ . "/last_generate", "w"); + fwrite($file, time()); + fclose($file); +} + diff --git a/php/icon.php b/php/icon.php index 4cfe671..6a7b499 100644 --- a/php/icon.php +++ b/php/icon.php @@ -17,15 +17,8 @@ if (!is_file($icon_path)) { } // generate facebook preview -if (!is_file($preview_path)) { - $image = new Imagick(); - $image->setBackgroundColor(new ImagickPixel('#ffffff')); - $image->readImageBlob(file_get_contents($icon_path)); - $image->setImageFormat("png24"); - $image->setImageInterpolateMethod(Imagick::INTERPOLATE_INTEGER); - $image->resizeImage(180, 180, Imagick::FILTER_POINT, 1); - $image->borderImage('#ffffff', 510, 225); - $image->writeImage($preview_path); +if (!is_file($preview_path) || filemtime($preview_path) < filemtime($icon_path)) { + require_once(__DIR__ . "/generate-preview.php"); $preview_mtime = time(); } else { $preview_mtime = filemtime($preview_path); diff --git a/php/index.php b/php/index.php index eb86c92..07e364b 100644 --- a/php/index.php +++ b/php/index.php @@ -102,4 +102,14 @@ $files = array_map(function ($file) { })() - \ No newline at end of file + + /dev/null 2>&1 &'); +} \ No newline at end of file