Sådan:
<?php
//http://exp.dk/spm/673617
function LoadJpeg($imgname)
{
$im = @imagecreatefromjpeg($imgname); /* Attempt to open */
if(!$im)
{
/* See if it failed */
$im = imagecreate(150, 30); /* Create a blank image */
$bgc = imagecolorallocate($im, 255, 255, 255);
$tc = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 150, 30, $bgc);
/* Output an errmsg */
imagestring($im, 1, 5, 5, "Error loading $imgname", $tc);
}
return $im;
}
header("Content-type: image/jpeg");
$botFile = "
http://www.wbadmorgan.co.uk/page_components/rainbow.jpg";$topFile = "
http://media.nasaexplores.com/lessons/03-027/images/sun.jpg";$botImg = LoadJpeg($botFile);
$topImg = LoadJpeg($topFile);
//Height/Width Bottom Picture
$botWidth = imagesx($botImg);
$botHeight = imagesy($botImg);
//Height/Width Top Picture
$topWidth = imagesx($topImg);
$topHeight = imagesy($topImg);
//Calculate the middle
$topX = round(($botWidth-$topWidth)/2);
$topY = round(($botHeight-$topWidth)/2);
imagecopymerge($botImg, $topImg, $topX, $topY, 0, 0, $topWidth, $topHeight, 100);
imagejpeg($botImg);
imagedestroy($botImg);
imagedestroy($topImg);
?>
Det bliver pænest hvis du bruger et transparent png i som topimg/topfile.
Du kan se eksemplet her:
http://www.codebreaker.dk/exp/673617.php