我假设插件通过 PHP 在服务器上编辑图像?如果是这样,您需要进行一些特殊调用来保留 PNG 图像中的 alpha 透明度:
$x = $_GET["x"];
$y = $_GET["y"];
$w = $_GET["w"];
$h = $_GET["h"];
// Load the original image.
$img = imagecreatefrompng($img_path);
imagealphablending($img, true);
// Create a blank canvas for the cropped image.
$img_cropped = imagecreatetruecolor($w, $h);
imagesavealpha($img_cropped, true);
imagealphablending($img_cropped, false);
$transparent = imagecolorallocatealpha($img_cropped, 0, 0, 0, 127);
imagefill($img_cropped, 0, 0, $transparent);
// Crop the image and store the data on the blank canvas.
imagecopyresampled($img_cropped, $img, 0, 0, $x, $y, $w, $h, $w, $h); // or imagecopy()
// Save the image.
imagepng($img_cropped, "image_cropped.png", 2);
// Free memory.
imagedestroy($img);
imagedestroy($img_cropped);
这在讨论 PHP 的 imagecopyresampled() here 时曾多次提及。