我试了这样的,但它只是使图像的背景变白,而不一定是使图像alpha。我想只是上传所有的JPG格式,所以如果我能以某种方式“透明地”压缩一个PNG图像,默认它只是白色,所以我可以用它作为JPG。
$ old = imagecreatefrompng($ upload);
$ background = imagecolorallocate($ old,255,255,255);
imagefill($ old,0,0,$ background);
imagealphablending($ old,false);
imagesavealpha($ old,true);
发布于 2018-02-24 10:36:30
<?php
$input_file = "test.png";
$output_file = "test.jpg";
$input = imagecreatefrompng($input_file);
list($width, $height) = getimagesize($input_file);
$output = imagecreatetruecolor($width, $height);
$white = imagecolorallocate($output, 255, 255, 255);
imagefilledrectangle($output, 0, 0, $width, $height, $white);
imagecopy($output, $input, 0, 0, 0, 0, $width, $height);
imagejpeg($output, $output_file);
https://stackoverflow.com/questions/-100007418
复制相似问题