Ajax Image Upload and a Watermark

This seems like the dumbest most simple thing but I can’t figure out what I’m screwing up - I’ve inherited a piece of javascript that does an Ajax upload and it does that fine

my save is a custom class but it works fine

save($_SERVER{'DOCUMENT_ROOT'}."/myimagespath/".$uploaded[0]);

I then put a ref to the file into my db

Insert into blah myimage='myimagespath/".$uploaded[0]."' WHERE);

This also works fine - now I need to take a transparent gif and stick it on top of this and save it into the same folder something like

'myimagespath/watermarked_".$uploaded[0]."

I found this script online but its not the kind of script that’s called from AJAX I just want the script to save the watermarked file and return true or false NOT the image -


function allthestuffthatsavestheoriginalimage()
{
 ....All the stuff that saves then...
   watermark($uploaded[0]);
}
function watermark($watermarkedFileName)
   {
      $filename = $watermarkedFileName;
      $watermark = "watermark.gif";
      $DestinationFile = "/myimagespath/watermarked_".$watermarkedFileName;

      $dest = imagecreatefromjpeg($filename);
      $src = imagecreatefromgif($_SERVER{'DOCUMENT_ROOT'}."/img/".$watermark);

      list($width, $height, $type, $attr) = getimagesize($filename);

      list($markwidth, $markheight, $type1, $attr1)=getimagesize($watermark);

      // Copy and merge
      $opacity = 30;
      imagecopymerge($dest, $src, ($width-$markwidth)>>1, ($height-$markheight)>>1, 0, 0, $markwidth, $markheight, $opacity);

      if ($DestinationFile<>'') {
         imagejpeg ($dest, $DestinationFile, 100);
      }
      
    
      // Output and free from memory
      header('Content-Type: image/jpeg');
      imagegif($dest);

      imagedestroy($dest);
      imagedestroy($src);
      return true;
   }

Try removing these 2 lines:

header(‘Content-Type: image/jpeg’);
imagegif($dest);

You’re sending a jpeg header but rendering it as a gif with imagegif.

Sweet - Works - Thanks