Originariamente inviato da Gunn
prova a modificare questo, supporta anche il canale alpha delle png
<?php
$image = "test.png";
$overlay = 'test2.png';
if (!file_exists($image)) {
die("Image does not exist.");
}
$w_offset = 0;
$h_offset = 0;
$extension = strtolower(substr($image, strrpos($image, ".") + 1));
switch ($extension)
{
case 'jpg':
$background = imagecreatefromjpeg($image);
break;
case 'jpeg':
$background = imagecreatefromjpeg($image);
break;
case 'png':
$background = imagecreatefrompng($image);
break;
case 'gif':
$background = imagecreatefromgif($image);
break;
default:
die("Image is of unsupported type.");
}
$swidth = imagesx($background);
$sheight = imagesy($background);
imagealphablending($background, true);
$overlay = imagecreatefrompng($overlay);
$owidth = imagesx($overlay);
$oheight = imagesy($overlay);
imagecopy($background, $overlay, $swidth - $owidth - $w_offset, $sheight - $oheight - $h_offset, 0, 0, $owidth, $oheight);
header("Content-type: image/jpeg");
header("Content-Disposition: filename=" . $image);
imagepng($background);
imagedestroy($background);
imagedestroy($overlay);
?>