使用php中的函数 imagecolortransparent 不能将图片背景透明化
环境: windows 7 Apache/2.4.25 (Win32) OpenSSL/1.0.2k PHP/5.6.16
<?php
$src_img=imagecreatefromjpeg('./images/Tulips.jpg');
$w=imagesx($src_img);
$h=imagesy($src_img);
$dest_w=(int)$w/2;
$dest_h=(int)$h/2;
$dest_img=imagecreatetruecolor(555,555);
$color=imagecolorallocate($dest_img,22,193,0);
$color=imagecolortransparent($dest_img,$color);
imagefill($dest_img,0,0,$color);
imagecopyresampled($dest_img, $src_img, 0, 0, 0, 0, $dest_w, $dest_h, $w, $h);
header("Content-Type:image/jpeg");
imagepng($dest_img);
将
$color=imagecolorallocate($dest_img,22,193,0);
修改为:
$color=imagecolorexact($dest_img,22,193,0);