png image copied to another image php -
i'm trying add png image onto image. problem have png image creating transparent background around instead of having background of other image.
here's image:
expected result:
this code:
<?php $img_name = "image_" . date("u") . ".png"; $whoareyou_src = imagecreatefrompng('who-are-you.png'); create_image($img_name, $whoareyou_src); print "<img src=". $img_name .">"; function create_image($img_name, $whoareyou_src) { $im = @imagecreate(800, 610) or die("cannot initialize new gd image stream"); $background_color = imagecolorallocate($im, 0, 128, 128); // teal // imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h ) $success = imagecopy($im, $whoareyou_src, 0, 0, 0, 0, imagesx($whoareyou_src), imagesy($whoareyou_src)); echo "image copy: " . $success . "<br>"; // testing imagepng($im, $img_name); imagedestroy($im); imagedestroy($whoareyou_src); } ?>
i thought of setting background transparent might help:
imagecolortransparent($whoareyou_src, imagecolorallocate($whoareyou_src, 0, 0, 0));
but did not change anything.
update
tried use imagecopyresampled
, alpha
settings still same result:
<?php $img_name = "image_" . date("u") . ".png"; $whoareyou_src = imagecreatefrompng('who-are-you.png'); create_image($img_name, $whoareyou_src); print "<img src=". $img_name .">"; function create_image($img_name, $whoareyou_src) { $im = @imagecreate(800, 610) or die("cannot initialize new gd image stream"); imagealphablending($im, false); imagesavealpha($im,true); $background_color = imagecolorallocate($im, 0, 128, 128); // teal $success = imagecopyresampled($im, $whoareyou_src, 0, 0, 0, 0, imagesx($whoareyou_src), imagesy($whoareyou_src), imagesx($whoareyou_src), imagesy($whoareyou_src)); echo "image copy: " . $success . "<br>"; imagepng($im, $img_name); imagedestroy($im); imagedestroy($whoareyou_src); } ?>
try this...
create_image($img_name, $whoareyou_src); print "<img src=". $img_name .">"; function create_image($img_name, $whoareyou_src) { $im = @imagecreatetruecolor(800, 610) or die("cannot initialize new gd image stream"); imagealphablending($im, false); imagesavealpha($im,true); $background_color = imagecolorallocate($im, 0, 128, 128); // teal // imagecopy ( resource $dst_im , resource $src_im , int $dst_x , int $dst_y , int $src_x , int $src_y , int $src_w , int $src_h ) $success = imagecopyresampled($im, $whoareyou_src, 0, 0, 0, 0, imagesx($whoareyou_src), imagesy($whoareyou_src)); echo "image copy: " . $success . "<br>"; // testing imagepng($im, $img_name); imagedestroy($im); imagedestroy($whoareyou_src); }
?>
Comments
Post a Comment