Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Creating A Watermark Image Using PHP GD Library (Part 2)

Introduction As the necessity of graphics draw is invading the web development space. Watermark Images are being demanded most time in software development. Now PHP made it easy for people to be able to use the stack to create watermark Images by just writing PHP codes. So, without wasting much of your time, let’s jump straight into this tutorial.How to create a watermark Image in PHP using PHP GD PHP GD library has several amazing features that enable image manipulation. Images can be cropped, resized, rotated, watermarked, and more. using PHP GD. In most web applications, you need to add dynamic images or add a watermark to images. In a previous tutorial, we explored How to Generate An Image: Using PHP GD Library. This guide will teach you how to use PHP to add watermarks to photos. We can use the GD extension in PHP to add a watermark to images using the following steps: Open the original image: $img = imagecreatefromjpeg(“IMAGE.JPG”); Set the text color: $red = imagecolorallocatealpha($img, 255, 0, 0); Add the text to the image: imagettftext($img, 18, 0, 0, 24, $red, “PATHFONT.TTF”, “COPYRIGHT”); Save the watermarked image: imagejpeg($img, “WATERMARKED.JPG”, 60); There are several things you can use GD Library to build, in this tutorial we will be building images that have watermarks! Below are examples of GD library watermarks. Build a watermark image that can be outputted as a file with the GD library With PHP GD there are so many things that can be achieved with the library, that’s why GD is an outstanding side of PHP. Examples of some use cases of GD library For generating images For generating watermark images For generating captcha Now, we will build a watermark that will be outputted as a file in our folder and browser.First, you start a session and a redirect that will take us to another page where we will view the image. we can achieve that with the header location, then we can visibly view the code. Next, you create a variable that the image will be assigned. See the code below. Then you will assign values to a list of variables in one operation. Assign **imagecreatefromstring()** method to a variable inside the imagecreatefromstring(). You will use another function to get the content of the image. In our case, we will use the file_get_content() to retrieve the image name, in our case we assigned it to a variable $image, and the file gets content that will contain a variable.The Imagecreatefromstring() the function provides an image identification that corresponds to the picture created using the provided data.The code below is a typical example of what’s explained above. Now, let’s copy and merge the parts of the image. What the function below does is that it takes the image variable and the watermark image variable, and then merges them with other variables and values that were stated in the codes above.After collecting all these values the function will combine them to make it one so that we can be able to call one variable at the end of the day.See the codes below. After going through the process of the imagecopymerge(“) function, we can handle or do with one variable.Now we want the image shown as a png file.  » Read More

The post Creating A Watermark Image Using PHP GD Library (Part 2) appeared first on Fresh For Designers..



This post first appeared on Fresh For Designers, please read the originial post: here

Share the post

Creating A Watermark Image Using PHP GD Library (Part 2)

×

Subscribe to Fresh For Designers

Get updates delivered right to your inbox!

Thank you for your subscription

×