This is png image:
This is jpg image:
Both are same width and height.
Expected output:
Code that I am using:
<?php
header('content-type: image/jpeg');
if(isset($_GET['source'])){
$source = $_GET['source'] ;
$watermark = imagecreatefrompng('png.png');
$watermark_height = imagesy($watermark);
$watermark_width = imagesx($watermark);
$image = imagecreatetruecolor($watermark_width,$watermark_height);
$image = imagecreatefromjpeg($source);
imagecopymerge($image, $watermark, 0, 0, 0, 0, $watermark_width, $watermark_height, 100 );
imagepng($image);
}
?>
Current output:
Could you help me to get my expected output?
You have to enable the alpha channel. To use the merge function and to keep the alpha channel, you can use the function published here: https://www.php.net/manual/en/function.imagecopymerge.php#92787
Your code will look like this:
Otherwise the alpha channel is filled with a color and your background gets completely filled.
Be careful: You also mix up content-type image/jpeg and the output function imagepng. (I've chosen image/png & imagepng in my solution.)