title: How do I add the watermark image with different positions in PHP Laravel?
body: <p>Hi I want to add <strong>watermark image</strong> with different positions like </p>
  
  <p><code>top-left</code>,<br>
  <code>top-right</code>,<br>
  <code>bottom-left</code>,<br>
  <code>bottom-right</code>,<br>
  <code>center</code>. </p>
  
  <p>Admin select one of the above position in the <code>setting</code> tab. I am using the <code>Orakuploader</code> plugin and in that plugin the watermark occur is in the <strong>center</strong> of the uploaded image.</p>
  
  <p>Here is the code of <strong>watermark image</strong> for <strong><code>center</code></strong> position:</p>
  
  <pre><code>function addWatermark($watermark, $imageDirectory, $imageName, $x = 0, $y = 0)
  {
      if(file_exists($watermark))
      {
          $marge_right  = 0;
          $marge_bottom = 0;
  
          $stamp = imagecreatefrompng($watermark);
  
          $image_extension = @end(explode(".", $imageName));
          switch($image_extension)
          {
              case "jpg":
                  $im = imagecreatefromjpeg("$imageDirectory/$imageName");
                  break;
              case "jpeg":
                  $im = imagecreatefromjpeg("$imageDirectory/$imageName");
                  break;
              case "png":
                  $im = imagecreatefrompng("$imageDirectory/$imageName");
                  break;
          }
  
          $imageSize = getimagesize("$imageDirectory/$imageName");
          $watermark_o_width = imagesx($stamp);
          $watermark_o_height = imagesy($stamp);
  
          $newWatermarkWidth = $imageSize[0];
          $newWatermarkHeight = $watermark_o_height * $newWatermarkWidth / $watermark_o_width;
  
  
          if((int)$x &lt;= 0)
              $x = $imageSize[0]/2 - $newWatermarkWidth/2;
          if((int)$y &lt;= 0)
              $y = $imageSize[1]/2 - $newWatermarkHeight/2;
  
          imagecopyresized($im, $stamp, $x, $y, 0, 0, $newWatermarkWidth, $newWatermarkHeight, imagesx($stamp), imagesy($stamp));
  
          switch($image_extension)
          {
              case "jpg":
                  header('Content-type: image/jpeg');
                  imagejpeg($im, "$imageDirectory/$imageName", 100);
                  break;
              case "jpeg":
                  header('Content-type: image/jpeg');
                  imagejpeg($im, "$imageDirectory/$imageName", 100);
                  break;
              case "png":
                  header('Content-type: image/png');
                  imagepng($im, "$imageDirectory/$imageName");
                  break;
          }
      }
  }
  </code></pre>
  
  <p>How to add watermark with rest of the positions like (<code>top-left</code>, <code>top-right</code>, <code>bottom-left</code> and <code>bottom-right</code>)? </p>
  
  <p>Much appreciated for your help. Thanks</p>