title: Adding watermark to image in PHP
body: <p>Basically, I have 2 php script. 1 of the php scripts is to display and the other 1 is the watermark function. </p>
  
  <p>I use this PHP to display the image with watermark:</p>
  
  <pre><code>&lt;img src="watermark1.php?image=photo.jpg&gt;
  </code></pre>
  
  <p>This is my watermark1.php:</p>
  
  <pre><code>&lt;?php
  // this tells the browser to render jpg image
  header('content-type: image/jpeg'); 
  
  // getting the image name from GET variable
  $image = $_GET['image']; 
  
  // creating png image of watermark
  $watermark = imagecreatefrompng('watermark.png');   
  
  // getting dimensions of watermark image
  $watermark_width = imagesx($watermark);
  $watermark_height = imagesy($watermark);  
  
  // creating jpg from original image
  $image_path =  $image;
  $image = imagecreatefromjpeg($image_path);
  //something went wrong
  if ($image === false) {
      return false;
  }
  // getting the dimensions of original image
  $size = getimagesize($image_path);
  // placing the watermark 5px from bottom and right
  $dest_x = $size[0] - $watermark_width - 5;
  $dest_y = $size[1] - $watermark_height - 5;
  // blending the images together
  imagealphablending($image, true);
  imagealphablending($watermark, true);
  // creating the new image
  imagecopy($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height);
  imagejpeg($image);
  // destroying and freeing memory
  imagedestroy($image);
  imagedestroy($watermark);
  ?&gt;
  </code></pre>
  
  <p>However, the watermarked image could not be displayed. I heard about GDLibrary and ImageMagicK but i have no idea what are these 2 about. Is there a way to add watermark just by adding php codes or is it a must to import the GDLibrary/ImageMagicK.</p>
  
  <p>Thanks for taking your time.</p>