I have a website where users are able to upload photos directly to the site. I created the following script to add a watermark to these photos automatically. It works fine when users upload. However, I am trying to write a new page with the same script so I can change all of the watermarks (website changed names). I am unable to make it work on the new page, yet it is copied directly from the original that works. Here is the script:
$ImageHW = GetImageSize("/home/locophot/public_html/pix/" . $FileName . ".jpg");
$ImageW = $ImageHW[0];
$ImageH = $ImageHW[1];
$wm_left = $ImageW - 143; // watermark left and top
$wm_top = $ImageH - 40;
$pix = "/home/locophot/public_html/pix/" . $FileName . ".jpg";
watermark($pix, $pix, "images/LocoPhotosWaterMark.png",$wm_left, $wm_top, 85);
function watermark($srcfilename, $newname, $watermark,$wm_left, $wm_top, $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 = $wm_left;
$vertmargin = $wm_top;
$photoImage = ImageCreateFromJPEG($srcfilename);
ImageAlphaBlending($photoImage, true);
$logoImage = ImageCreateFromPNG($watermark);
$logoW = ImageSX($logoImage);
$logoH = ImageSY($logoImage);
ImageCopy($photoImage, $logoImage, $horizmargin, $vertmargin, 0, 0, $logoW, $logoH);
ImageJPEG($photoImage,$newname, $quality);
ImageDestroy($photoImage);
ImageDestroy($logoImage);
}
I get this error when trying to run this script:
Warning: imagejpeg(): Unable to open '/home/locophot/public_html/pix/01000326030659.jpg' for writing in /home/locophot/public_html/AddLogo.php on line 51
(Line 51 is this line: ImageJPEG($photoImage,$newname, $quality)😉
Any ideas what is going on? Folders are set with the appropriate permissions, etc. Again, it works fine on the original page, errors on this page.
Thanks for the help!
~Matthew