Hi!
I'm trying to add a copyright image(watermark) on another image while uploading .. It doesn't work at all, can anyone pls tell me whatz wrong with this?
Thanks!
Uploading Code:
//watermark code
function watermark($srcfilename, $newname) {
$watermark="images/watermark.png";
$quality="100";
$imageInfo = getimagesize($srcfilename);
$width = $imageInfo[0];
$height = $imageInfo[1];
$logoinfo = getimagesize($watermark);
$logowidth = $logoinfo[0];
$logoheight = $logoinfo[1];
$horizextra =$width - $logowidth;
$vertextra =$height - $logoheight;
$horizmargin = round($horizextra / 2);
$vertmargin = round($vertextra / 2);
$photoImage = ImageCreateFromJPEG($srcfilename);
ImageAlphaBlending($photoImage, true);
$logoImage = ImageCreateFromPNG($watermark);
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
ImageCopy($photoImage, $logoImage, ImageSX($photoImage)-$logoW, ImageSY($photoImage)-$logoH, 0, 0, $logoW, $logoH);
//ImageJPEG($photoImage); // output to browser
ImageJPEG($photoImage,"wallpapers/".$newname, $quality);
ImageDestroy($photoImage);
ImageDestroy($logoImage);
}
//filename
$filename = $_FILES['filetoupload']['name'];
if (watermark($_FILES['filetoupload']['tmp_name'], $filename)) {
//file has been uploaded
echo "File <b>$filename </b> uploaded!";
exit();
}