Question

I have tried many solutions and the truth and got to the point where you do not know what else to do.

The following image is a PNG ("cover.png"):

cover.png

As you will have a blank oval really is completely transparent. With PHP I'm trying to fuse it to this picture ("lapiz.jpg"):

lapiz.jpg

However, despite how much I've tried to not get the clear space of the first image is transparent and instead goes completely blank, covering the image that should melt.

For now this is my code:

$img_user = 'fotos/lapiz.jpg';
$img_user_type = getImageInfo($img_user,'type');
$posX = 404;
$posY = 2;
$width = getImageInfo($img_user,'width');
$height = getImageInfo($img_user,'height');

$stamp = 'fotos/cover.png';

switch($img_user_type)
 {
    case 'jpeg':
        $img_user_create = imagecreatefromjpeg($img_user);
        break;
    case 'gif':
        $img_user_create = imagecreatefromgif($img_user);
        break;
    case 'png':
        $img_user_create = imagecreatefrompng($img_user);
        break;
}

$im = imagecreatefrompng($stamp);

imagealphablending($im, false);
imagesavealpha($im, true); 

imagecolortransparent($im, imagecolorallocate($im, 255, 255, 255));

imagecopymerge($img_user_create, $im, $posX, $posY, 0, 0, $width, $height, 100);

header('Content-Type: image/png');
imagepng($im);

ImageDestroy($im);
ImageDestroy($img_user_create);

What I can be doing wrong?

Was it helpful?

Solution

junihh resolved this using the imagemagick library and the code below:

$img1 = new Imagick('fotos/lapiz.jpg'); 
$img2 = new Imagick('fotos/cover.png'); 
$posX = 404; 
$posY = 2; 
$img2->compositeImage( $img1, imagick::COMPOSITE_DSTOVER, $posX, $posY ); 

header('Content-type: image/png'); 
echo($img2);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top