In the web earth, Watermark is the 1 way to protect our image from being theft or re-used by another user. So, if you want create your ownership on image, for this y'all take to add together watermark on an image. There are some another benefits of put watermark on your prototype is that it will identify that item image or photo is created or uploaded by you. In nearly of the website, logo is used as watermark and put on image. For this all feature hither in this mail service, we will show you how to add watermark to image using PHP.

Now in your listen how can we add watermark to a prototype in PHP. So, we tin can implement put watermark on paradigm while uploading of Epitome using PHP. PHP has GD library which has provides the states simple way to add a watermark paradigm to any photo by using blastoff channels. Here nosotros volition make add dynamic watermark on prototype feature will helps you to manage epitome direction section. In this tutorial, we will first upload image on server and add watermark to image using PHP.

For make Add together watermark on Image using PHP script, here we will write PHP script, that will process two images, ane will exist the prototype which we will upload through form, and second will be logo or business stamp which we will be use as watermark epitome. In PHP script first it will upload select image file to server and then after by using PHP GD library function watermark prototype volition be put on uploaded image. Mostly, nosotros have to use transparent prototype has been used as watermark image, and so it has easily placed on uploaded image. So, this mail service main target is that to larn How to add a watermark to Epitome using PHP. Below you can find source code of this tutorial.

Source Lawmaking


index.php


                              <?php  //alphabetize.php  $connect = new PDO("mysql:host=localhost;dbname=testing", "root", "");  $message = '';  if(isset($_POST["upload"])) {   if(!empty($_FILES["select_image"]["name"]))   {      $extension = pathinfo($_FILES["select_image"]["name"],PATHINFO_EXTENSION);          $allow_extension = array('jpg','png','jpeg');      $file_name = uniqid() . '.' . $extension;      $upload_location = 'upload/' . $file_name;      if(in_array($extension, $allow_extension))     {       $image_size = $_FILES["select_image"]["size"];       if($image_size < 2 * 1024 * 1024)       {         if(move_uploaded_file($_FILES["select_image"]["tmp_name"], $upload_location))         {                       $watermark_image = imagecreatefrompng('circular-logo.png');           if($extension == 'jpg' || $extension == 'jpeg')           {             $paradigm = imagecreatefromjpeg($upload_location);           }            if($extension == 'png')           {             $image = imagecreatefrompng($upload_location);           }            $margin_right = 10;            $margin_bottom = 10;            $watermark_image_width = imagesx($watermark_image);            $watermark_image_height = imagesy($watermark_image);              imagecopy($image, $watermark_image, imagesx($epitome) - $watermark_image_width - $margin_right, imagesy($prototype) - $watermark_image_height - $margin_bottom, 0, 0, $watermark_image_width, $watermark_image_height);             imagepng($image, $upload_location);             imagedestroy($paradigm);           if(file_exists($upload_location))           {              $message = "Image Uploaded with Watermark";             $information = array(               ':image_name'   =>  $file_name             );             $query = "             INSERT INTO images_table              (image_name, upload_datetime)              VALUES (:image_name, now())             ";             $statement = $connect->fix($query);             $argument->execute($data);           }           else           {              $message = "There is some mistake, try again";           }         }         else         {           $message = "There is some error, try again";         }       }       else       {         $bulletin = "Selected Image Size is very big";       }           }     else     {       $message = 'Only .jpg, .png and .jpeg prototype file allowed to upload';     }   }   else   {      $message = 'Please select Epitome';   }  }  $query = " SELECT * FROM images_table  Gild BY image_id DESC ";  $statement = $connect->prepare($query);  $statement->execute();  $event = $statement->fetchAll();    ?>  <!DOCTYPE html> <html>   <caput>     <title>How to Dynamically Add Watermark to Image using PHP</championship>     <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.iii.1/jquery.js"></script>     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/three.3.6/css/bootstrap.min.css" />   </caput>   <body>     <br />     <div grade="container">       <h3 align="center">How to Dynamically Add Watermark to Prototype using PHP</h3>       <br />       <?php       if($message != '')       {         echo '         <div course="alarm alert-info">         '.$bulletin.'         </div>         ';       }       ?>       <div class="panel panel-default">         <div grade="panel-heading">Add together Wartermark to an Image</div>         <div class="panel-body">           <form method="post" enctype="multipart/form-data">             <div class="row">               <div class="form-group">                 <characterization class="col-doc-6" marshal="correct">Select Paradigm</label>                 <div class="col-medico-half-dozen">                   <input type="file" name="select_image" />                 </div>               </div>                           </div>             <br />             <div form="form-group" marshal="center">               <input type="submit" name="upload" grade="btn btn-primary" value="Upload" />             </div>           </form>         </div>       </div>       <div class="console console-default">         <div class="panel-heading">Uploaded Prototype with Watermark</div>         <div course="panel-trunk" fashion="elevation: 700px;overflow-y: auto;">           <div form="row">           <?php           foreach($result as $row)           {             echo '             <div class="col-md-2" mode="margin-bottom:16px;">               <img src="upload/'.$row["image_name"].'" form="img-responsive img-thumbnail"  />             </div>             ';           }           ?>           </div>         </div>       </div>     </div>   </torso> </html>                          


Database


                              -- -- Database: `testing` --  -- --------------------------------------------------------  -- -- Tabular array structure for table `images_table` --  CREATE Table `images_table` (   `image_id` int(11) NOT Zip,   `image_name` varchar(250) Non Zippo,   `upload_datetime` datetime NOT Zilch ) ENGINE=InnoDB DEFAULT CHARSET=latin1;  -- -- Indexes for dumped tables --  -- -- Indexes for table `images_table` -- ALTER Table `images_table`   ADD PRIMARY Primal (`image_id`);  -- -- AUTO_INCREMENT for dumped tables --  -- -- AUTO_INCREMENT for tabular array `images_table` -- Change TABLE `images_table`   MODIFY `image_id` int(eleven) NOT Nix AUTO_INCREMENT;                          

With the help of above source code, you can brand one functionality like you can upload an image with watermark and save one server by using PHP. When you have upload epitome and then information technology volition automatically add watermark on epitome using PHP. You can also alter the position of watermark prototype by modify the value of margin offset, you tin add watermark on an paradigm at any position. By using this tutorial, you tin likewise add text every bit watermark to epitome using PHP