Der er en del overflødig kode hvis vi kun snakker vandmærke. Men her er den:
$tmpnavn = getdate();
$nytnavn = $tmpnavn["year"] . $tmpnavn["mon"] . $tmpnavn["mday"] . $tmpnavn["hours"] . $tmpnavn["minutes"] . $tmpnavn["seconds"] . RAND(0,999);
move_uploaded_file($_FILES['upfile']['tmp_name'],"bryster/$nytnavn.tmp");
$size = getimagesize("bryster/$nytnavn.tmp");
$width = $size["0"];
$height = $size["1"];
$filetype = $size["2"];
if($filetype==1 or $filetype==2)
{
if($width!=0 and $height!=0)
{
$dest_width_thumb = 120;
$dest_height_thumb = round($height/($width/$dest_width_thumb));
if($width>480)
{
$dest_width = 470;
$dest_height = round($height/($width/$dest_width));
}
else
{
$dest_width = $width;
$dest_height = $height;
}
if($filetype==1)
{
$sur = "gif";
$src_img = imagecreatefromgif("bryster/$nytnavn.tmp");
$dst_img = imagecreatetruecolor($dest_width_thumb,$dest_height_thumb);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width_thumb, $dest_height_thumb, $width, $height);
imagejpeg($dst_img, "bryster/thumbs/$nytnavn.jpg", 75);
$src_img = imagecreatefromgif("bryster/$nytnavn.tmp");
$dst_img = imagecreatetruecolor($dest_width,$dest_height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
imagejpeg($dst_img, "bryster/$nytnavn.jpg", 75);
imagedestroy($src_img);
imagedestroy($dst_img);
}
elseif($filetype==2)
{
$sur = "jpg";
$src_img = imagecreatefromjpeg("bryster/$nytnavn.tmp");
$dst_img = imagecreatetruecolor($dest_width_thumb,$dest_height_thumb);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width_thumb, $dest_height_thumb, $width, $height);
imagejpeg($dst_img, "bryster/thumbs/$nytnavn.jpg", 75);
$src_img = imagecreatefromjpeg("bryster/$nytnavn.tmp");
$dst_img = imagecreatetruecolor($dest_width,$dest_height);
imagecopyresampled($dst_img, $src_img, 0, 0, 0, 0, $dest_width, $dest_height, $width, $height);
$pic2 = ImageCreateFromGIF("graphics/watermark.gif");
$lsizeX = ImageSX($pic2);
$lsizeY = ImageSY($pic2);
// Udregn hvor billedet skal placeres (nederste højre hjørne her)
$posX = $dest_width - $lsizeX - 10;
$posY = $dest_height - $lsizeY - 10;
ImageCopyMerge($dst_img, $pic2, $posX, $posY, 0, 0, $lsizeX, $lsizeY, 100);
imagejpeg($dst_img, "bryster/$nytnavn.jpg", 75);
imagedestroy($src_img);
imagedestroy($dst_img);
}