Jump to content

Saving watermarked image


graham23s

Recommended Posts

Hi Guys,

 

Using this code i am able to overlay a logo onto an image:

 

<?php
   // Load the image where the logo will be embeded into
   $image = imagecreatefromjpeg("box.jpg");

   // Load the logo image
   $logoImage = imagecreatefrompng("logo.png");
   imagealphablending($logoImage, true);

   // Get dimensions
   $imageWidth=imagesx($image);
   $imageHeight=imagesy($image);

   $logoWidth=imagesx($logoImage);
   $logoHeight=imagesy($logoImage);	 

   // Paste the logo
   imagecopy(
      // source
      $image,
      // destination
      $logoImage,
      // destination x and y
      $imageWidth-$logoWidth, $imageHeight-$logoHeight,
      // source x and y
      0, 0,
      // width and height of the area of the source to copy
      $logoWidth, $logoHeight);

   // Set type of image and send the output
   //header("Content-type: image/png");
   //imagePng($image);
   imagejpeg($logoImage, "imageWithLogo.jpg", 100);
   
   // Release memory
   imageDestroy($image);
   imageDestroy($imageLogo);
?>

 

this part:

 

  //header("Content-type: image/png");

  //imagePng($image);

 

shows me the complete image with the logo ontop, what i'm having trouble with is saving the image.

 

any help would be appreciated

 

thanks guys

 

Graham

 

Link to comment
https://forums.phpfreaks.com/topic/213734-saving-watermarked-image/
Share on other sites

I think the part of that code that saves the actual image file on server is:

 

imagejpeg($logoImage, "imageWithLogo.jpg", 100);

 

if you call that in site root it would probably not work, I would try something like this:

 

imagejpeg($logoImage, "images/imageWithLogo.jpg", 100);

 

where "images" is a folder that is made writable.

I duno whats up but you got the source and destination in the wrong order in the imagecopy function, destination comes first, so you should be saving $image. Doesa file of that name already exist? Do you have error reporting and display errors on?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.