50 lines
1.3 KiB
PHP
50 lines
1.3 KiB
PHP
|
<?php
|
||
|
|
||
|
function generate_preview ($icon_path, $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);
|
||
|
}
|
||
|
|
||
|
$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);
|
||
|
}
|
||
|
|