public static function imageIco($gd, $targetPath) { $imagePath = tempnam(sys_get_temp_dir(), 'iconify'); imagepng($gd, $imagePath); $icoLib = new PHP_ICO($imagePath, [[16, 16]]); $icoLib->save_ico($targetPath); unlink($imagePath); }