php - Upload png image black background -
when upload png image php, background color of image setted black.
tried set transparent background doesn't work.
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); }
edited:
i tought i'v finished problem 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); }
imagecreatetruecolor()
creates image filled opaque black. unless fill new image transparency first, black show through later.
all need imagefill()
transparent colour - namely black, this:
imagefill($dst_r,0,0,imagecolorallocatealpha($dst_r, 0,0,0,127)); // transparency values range 0 127
applied code, should work:
if( $image_type == imagetype_png ) { $dst_r = imagecreatetruecolor($targ_w, $targ_h); imagealphablending($dst_r, false); imagesavealpha($dst_r, true); // paint watermark image transparent color remove default opaque black. // if don't black shows through later colours. 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); }
Comments
Post a Comment