Watch Youtube Video (HINDI) :
In his post, we will do how to add a watermark on the image using PHP. When you are working with the image application and want to add a watermark on the image then this post will help you to add it. it's simple to add a watermark logo on the image.
We will add the logo on the png image to take an example. Therefore we need two images, the first image is what you want to add as a watermark and the second thing is the main image on this image you want to add.
to get done watermark add to the image, we need to set the header content type for the image generated. then after we will give the width and height where you want to add the logo watermark.
Logo:
This is our simple logo.
Image:
This is our png image. On this image's bottom left I want to add above mentioned logo.
Code Example
You just create a simple PHP file. in this file paste all the given codes. You just need to give your image path and watermark image path add.
<?php header('content-type: image/png'); $sourceImage = 'image.png'; // ADD IMAGE PATH $myWatermark = imagecreatefrompng('logo.png'); // WATER MARK LOGO PATH $watermarkWidth = imagesx($myWatermark); $watermarkHeight = imagesy($myWatermark); $image = imagecreatefrompng($sourceImage); $imageSize = getimagesize($sourceImage); $wmX = $imageSize[0] - $watermarkWidth - 20; $wmY = $imageSize[1] - $watermarkHeight - 20; imagecopy($image, $myWatermark, $wmX, $wmY, 0, 0, $watermarkWidth, $watermarkHeight); imagepng($image, time().'.png'); // SAVE IMAGE imagepng($image); // SHOW IMAGE imagedestroy($image); imagedestroy($myWatermark);
Output With Watermark:
We always thanks to you for reading our blogs.
Dharmesh Chauhan
(Swapinfoway Founder)Hello Sir, We are brothers origin from Gujarat India, Fullstack developers working together since 2016. We have lots of skills in web development in different technologies here I mention PHP, Laravel, Javascript, Vuejs, Ajax, API, Payment Gateway Integration, Database, HTML5, CSS3, and Server Administration. So you need our service Please Contact Us
Haresh Chauhan
(Co-Founder)We Are Also Recommending You :
- How To Check Valid Integer Values Using PHP Function Example
- Sendgrid Email Send Tutorial Laravel/PHP/cURL Example
- Simple WhatsApp Messages Send Using Chat API In PHP
- How To Remove HTML Tags From The PHP String
- How to connect database with php
- Get IP PHP Function Example - ip_info()
- Zoom API Integration with PHP
- Call to undefined function Gregwar\Captcha\imagecreatetruecolor()
- PHP Post Request cURL Example With Authentication
- Firebase Notification Send Example