<?php
$source = __DIR__ . '/logo.png';
$outdir = __DIR__ . '/assets/icons';
$sizes = [48,72,96,144,192,256,384,512];

if (!is_dir($outdir)) mkdir($outdir, 0755, true);

$src = imagecreatefrompng($source);
$w = imagesx($src);
$h = imagesy($src);

foreach ($sizes as $s) {
    $dst = imagecreatetruecolor($s,$s);
    imagealphablending($dst,false);
    imagesavealpha($dst,true);
    $t = imagecolorallocatealpha($dst,0,0,0,127);
    imagefill($dst,0,0,$t);

    $scale = min($s/$w,$s/$h);
    $nw = $w*$scale;
    $nh = $h*$scale;
    imagecopyresampled(
        $dst,$src,
        ($s-$nw)/2,($s-$nh)/2,
        0,0,$nw,$nh,$w,$h
    );

    imagepng($dst,"$outdir/icon-{$s}x{$s}.png",9);
    imagedestroy($dst);
}
