Sha*_*awn 17 php gd image-manipulation image-processing
我试过这样的东西,但它只是使图像的背景变白,不一定是图像的alpha.我想只是将所有内容上传为jpg,所以如果我能以某种方式"透明化"某个png图像,将其默认为白色,这样我就可以将它用作jpg.感谢任何帮助.谢谢.
$old = imagecreatefrompng($upload); $background = imagecolorallocate($old,255,255,255); imagefill($old, 0, 0, $background); imagealphablending($old, false); imagesavealpha($old, true);
Ale*_*min 57
<?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);
Run Code Online (Sandbox Code Playgroud)