From 5c4d191d99dfd3cfbd2621308ea292abc1b234a4 Mon Sep 17 00:00:00 2001 From: AOAOSTAR <86001674+aoaostar@users.noreply.github.com> Date: Thu, 8 Dec 2022 16:17:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=F0=9F=90=9B=20png=20resize=20mistake?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/command/PluginLogoFormat.php | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/command/PluginLogoFormat.php b/app/command/PluginLogoFormat.php index 71daee5..23206a3 100644 --- a/app/command/PluginLogoFormat.php +++ b/app/command/PluginLogoFormat.php @@ -34,10 +34,8 @@ class PluginLogoFormat extends Command $logo = $plugin . '/logo.png'; $image_size = getimagesize($logo); if ($image_size[0] !== 200 || $image_size[1] !== 200) { + switch ($image_size[2]) { - case 1: - $image = imagecreatefromgif($logo); - break; case 2: $image = imagecreatefromjpeg($logo); break; @@ -45,16 +43,20 @@ class PluginLogoFormat extends Command $image = imagecreatefrompng($logo); break; default: - $image = imagecreatefromjpeg($logo); + goto over; } - $resource = imagescale($image, 200, 200); - imagealphablending($resource, false); - imagesavealpha($resource, true); - imagepng($resource, $logo); - unlink($plugin . '/logo_test.png'); + $new_image = imagecreatetruecolor(200, 200); + imagealphablending($new_image, false); + imagesavealpha($new_image, true); + $transparent = imagecolorallocatealpha($new_image, 255, 255, 255, 127); + imagefilledrectangle($new_image, 0, 0, 200, 200, $transparent); + imagecopyresampled($new_image, $image, 0, 0, 0, 0, 200, 200, $image_size[0], $image_size[1]); + imagepng($new_image, $logo); + imagedestroy($image); - imagedestroy($resource); + imagedestroy($new_image); } + over: $output->writeln("处理成功:[$plugin]"); }