Hello Reader's!
If you are looking to learn how to print the text over a image as a water mark then this blog is very helpful to you. Fixing a watermark on image can be used by PHP. So first we will learn how this process going in action.
Step 1. You need to create HTML form just as we develop for image uploading.
And it's code will be go like this:-
<html>
<title>This is the blog for fixing text watermark on image</title>
<body>
<form method="post" autocomplete = "off" action= "imageUplod.php" enctype="multipart/form-data">
<input type="file" class="btn btn-success " name ="placeImages" value="Select Photos" accept="image/*" required>
<input type="submit" value="Upload" name="submit" class="btn">
</form>
</body>
</html>
In the code above you also make Image type validation ensuring that your browser will not let you to select file other than images. Now we will start building the uploading and watermark process in the file with name imageUpload.php, And it's code will go like this:-
<?php
$image_name = $_FILES['placeImages']['name']; //file name
$image_size = $_FILES['placeImages']['size']; //file size
$image_temp = $_FILES['placeImages']['tmp_name']; //file temp
$image_type = $_FILES['placeImages']['type']; //file type
$image_name = str_replace(' ', '_', $image_name); //replacing all the blackspaces
$destination_folder = 'image/uplodingfoldername/';
$image_temp = $destination_folder.$i.$image_name;
$image = imagecreatefromjpeg($image_temp);
$color = imagecolorallocate($image, 255, 255, 255);
$string = 'THIS IS THE BLOG ON FINDNERD.COM'; //insert the text here for watermark
$fontSize = 6;
$x = 570; //this the x cordinate for text
$y = 430; //this is the y cordinate for text
imagestring($image, $fontSize, $x, $y, $string, $color);
$random_name = '';
$random_name = 'image/uplodingfoldername/'.$i.$image_name;
imagejpeg($image,$random_name,90); //save text watermark on image on disk
?>
So In the beginning of the code above you can see we are getting the image temp name, size, type and assiging the destination folder address where the process image will be uploaded.
$string = 'this is the blog on findnerd.com'; //insert the text here for watermark
$fontSize = 6;
$x = 570; //this the x cordinate for text
$y = 430; //this is the y cordinate for text
The above code is used to do customization of your text over the image. For example if yow want to write you just need to set it inside $sting var. Similarly $fontSize is for increasing or decreasing text size where as $x and $y are the horizontal and vertical points for creating the positions for the text. That's all we need to do.
And the output of this will be found inside the destination folder on which the text will be fixed on the same image.
0 Comment(s)