php add watermark to image
![]() |
Add Watermark to Image in PHP |
Hi Guys Today we are going to learn how to add watermark to image in php.
just follow the below example to learn php image watermark system
Your Files Structure:
--photos
--index.html
--process.php
--logo.png
![]() |
php add watermark to image |
Copy and User the below codes to implement php watermark system..
1. index.html
<html> <title>Add WaterMark To image Using PHP --codenair.com</title> <body> <h2>Add WaterMark To image Using PHP --codenair.com</h2> <form method="post" action="process.php" enctype="multipart/form-data"> <input type="file" name="imageupload"> <input type="submit" name="submit" value="upload"> </form> </body> </html>2. process.php
<?php if(isset($_POST['submit'])) { // Give the Complete Path of the folder where you want to save the image $folder="photos/"; move_uploaded_file($_FILES["imageupload"]["tmp_name"], "$folder".$_FILES["imageupload"]["name"]); $file='photos/'.$_FILES["imageupload"]["name"]; $uploadimage=$folder.$_FILES["imageupload"]["name"]; $newname=$_FILES["imageupload"]["name"]; // Set the thumbnail name $thumbnail =$folder."CodeNair-".$newname; $actual =$folder."CodeNair-".$newname; $imgname="CodeNair-".$newname; //Getting Image Extensio $imageinfo=$_FILES['imageupload']['type']; $extension=str_replace("image/","","$imageinfo"); // Load the mian im if($extension!="jpeg" && $extension!="png" && $extension!="gif"){ echo "Only jpeg,png and gif pic are allowed"; }else{ if($extension=='bmp'){ $source = imagecreatefromwbmp($uploadimage); } if($extension=='gif'){ $source = imagecreatefromgif($uploadimage); } if($extension=='jpeg'){ $source = imagecreatefromjpeg($uploadimage); } if($extension=='png'){ $source = imagecreatefrompng($uploadimage); } // load the image you want to you want to be watermarked $watermark = imagecreatefrompng('logo.png'); // get the width and height of the watermark image $water_width = imagesx($watermark); $water_height = imagesy($watermark); // get the width and height of the main image image $main_width = imagesx($source); $main_height = imagesy($source); // Set the dimension of the area you want to place your watermark we use 0 // from x-axis and 0 from y-axis $dime_x = 2; $dime_y = 2; // // copy both the images imagecopy($source, $watermark, $dime_x, $dime_y, 0, 0, $water_width, $water_height); // Final processing Creating The Image imagejpeg($source, $thumbnail, 75); } } ?> <img src='photos/<?php echo $imgname;?>'> <a href="index.html">Upload Another</a>That's it Guys How to Create a Nice PHP image watermark system..
![]() |
php add watermark to image |
Keep visiting for more codes and let me know your opinion.
Thank you..
No comments:
Post a Comment
Thank You for Your Comment
Note: Only a member of this blog may post a comment.