title: php watermark and save image
body: <p>I am trying to add a watermark to an image and then save the image to another file with php. This is the code that I have so far, but for some reason the watermark is not appearing on the image in the new directory. 
  The original image is saved in the path <code>$old_path</code> and I want to save it to <code>$new_path</code> after applying the watermark.</p>
  
  <pre><code>    $old_path = "images_upload/".$name.".".$type;
      $new_path = "images_main/".$name.".".$type;
      ////////////////////water mark
  $main_image = imagecreatefromstring(file_get_contents($old_path));
  
  // Load the logo image
  $logoImage = imagecreatefrompng("assets/watermark.png");
  imagealphablending($logoImage, true);
  
  // Get dimensions
  $imageWidth=imagesx($main_image);
  $imageHeight=imagesy($main_image);
  
  $logoWidth=imagesx($logoImage);
  $logoHeight=imagesy($logoImage); 
  
  // Paste the logo
  imagecopy(
     // source
     $main_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);
      ////////////////////////
  
      rename($old_path, $new_path);// save image
  </code></pre>
  
  <p>Please tell me what I am doing wrong.</p>