I was viewing the php manual but unsuccessfully to make it work 1 transparent image on top another image .jpg
$image1 = imagecreatefromjpeg('image.jpg');
$image2 = imagecreatefrompng('watermark.png');
imagecopy($image1, $image2, 0, 0, 0, 0, imagesx($image1), imagesy($image1));
imagejpeg($image1, "ok.jpg");
echo "<img src='ok.jpg' alt='test' >";
The two images have the same size the only difference and the second image is transparent and has a logo in a certain position
echo is only printing the first image
EDIT
imagecopymerge
$image1 = imagecreatefromjpeg('image.jpg');
$image2 = imagecreatefrompng('watermark.png');
imagecopymerge($image1, $image2, 0, 0, 0, 0, imagesx($image1), imagesy($image1, 5));
imagejpeg($image1, "ok.jpg");
echo "<img src='ok.jpg' alt='test' >";
IMAGES
ok.jpg - This should be the result, but only the T-shirt appears when it generates the file ok.jpg
This function should be helpful to you http://php.net/manual/en/function.imagecopymerge.php
You could try to reposition the logo/watermark.
You just have to get the coordinates (left and top) of four corners in the watermark.png and displace them to four coordinates of image.jpg:
$image = new Imagick('image.jpg');
$watermark = new Imagick('watermark.png');
$controlPoints = [
300,1700 /* watermark.png (left,top) coordinate moves to image.jpg (left,top) coordinate */ 800,900, // TOP LEFT CORNER
1963,1700, /* to */ 1450,900, // TOP RIGHT CORNER
1963,2500, /* to */ 1450,1100, // BOTTOM RIGHT CORNER
300,2500, /* to */ 800,1100, // BOTTOM LEFT CORNER
];
$watermark->distortImage(Imagick::DISTORTION_BILINEAR, $controlPoints, false);
$image->addImage($watermark);
$result = $image->mergeImageLayers(Imagick::LAYERMETHOD_MERGE);
echo '<img src="data:image/jpg;base64,'. base64_encode($result->getImageBlob()) . '" alt="test" />';
You can play freely with the control points.
But be careful if you use images with different sizes because if one of the destination coordinates goes outside the size of the image to distort (the watermark) you must change to:
$watermark->distortImage(Imagick::DISTORTION_PERSPECTIVE, $controlPoints, true);
You have to change the first and the third arguments.