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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.