I've tried numerous times to figure out how to do this. I have a script that takes a file, makes a smaller thumbnail, and copies over the larger image... kinda like a photo album i guess you could say. I have code now that will put a watermark on which is in another script... i have no idea how to get the watermarking code to work right on my album script. Maybe some of you could help:
Heres a portion of the script that will take an image, make a thumbnail and copy over the orig. image:
$newImage=imageCreateTrueColor(160,120); //GD2 Function
ImageCopyResampled($newImage,$oldImage,0,0,0,0,160,120,imageSX($oldImage),imageSY($oldImage)); // GD2 Function
imagePNG($newImage,"/home/virtual/site3/fst/var/www/html/imgupload/$date.$rand.png");
move_uploaded_file($_FILES['userfile']['tmp_name'],"/home/virtual/site3/fst/var/www/html/imgupload/$date.$rand.$type");
imagedestroy($oldImage);
imagedestroy($newImage);
Here is the other script that makes a watermark on an image:
<?php
$watermark = "proof150.png";
$quality = "75";
$imagedir = "images";
$workingdir = opendir ($imagedir);
while ($entry = readdir($workingdir)) {
if(eregi(".+.jpe?g$", $entry )) {
$i=1;
watermark($imagedir."/".$entry, $entry, $watermark, $quality);
$i++;
}
}
//$filename should be a JPG and $watermark a PNG-24 with alpha transparency. $quality is 1-100 JPG quality on output.
function watermark($srcfilename, $newname, $watermark, $quality) {
$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,"images/watermarked/wm_".$newname, $quality);
ImageDestroy($photoImage);
ImageDestroy($logoImage);
}
?>
This code above takes all images in a directory and watermarks them. I want to modify the code to work with the first script, and to put the watermark on the image that is copied over; not the watermark.
Anybody know how to do this? Thanks in advance for the help.