When i upload a png image with php, the background color of the image is setted to black.
I tried to set it to transparent background but it doesn't work.
This is my code :
if( $image_type == IMAGETYPE_PNG )
{
$dst_r = ImageCreateTrueColor($targ_w, $targ_h);
imagealphablending($dst_r, false);
imagesavealpha($dst_r, true);
imagefill($dst_r,0,0,imagecolorallocatealpha($dst_r, 0,0,0,127));
imagecopyresampled($dst_r, $this->image, 0, 0, $targ_x, $targ_y, $targ_w, $targ_h, $targ_w, $targ_h);
imagepng($dst_r,$filename, 9);
}
I tought i'v finished with this problem but i was wrong:
$targ_w_thumb = $targ_h_thumb = 220;
if($image_type == IMAGETYPE_PNG)
{
$dst_r = ImageCreateTrueColor($targ_w_thumb, $targ_h_thumb);
imagealphablending($dst_r, false);
imagesavealpha($dst_r, true);
imagefill($dst_r,0,0,imagecolorallocatealpha($dst_r, 0,0,0,127));
imagecopyresampled($dst_r, $this->image, 0, 0, $targ_x, $targ_y, $targ_w_thumb, $targ_h_thumb, $targ_w, $targ_h);
imagepng($dst_r,$filename, 9);
}
I dont know why but when i added targ_w_thumb its work fine + imagefill():
$targ_w_thumb = $targ_w_thumb = 200;
$dst_r = ImageCreateTrueColor($targ_w_thumb, $targ_h_thumb);
imagealphablending($dst_r, false);
imagesavealpha($dst_r, true);
imagefill($dst_r,0,0,imagecolorallocatealpha($dst_r, 0,0,0,127));
imagecopyresampled($dst_r, $this->image, 0, 0, $targ_x, $targ_y, $targ_w_thumb, $targ_h_thumb, $targ_w, $targ_h);
imagepng($dst_r,$filename, 9);