SlideShare a Scribd company logo
How to Hide Admin Bar in
WordPress?
How to Duplicate Pages OR Posts in
WordPress?
How to Test Internet Speed Using
Python?
Twitter Search API Example Using
PHP
How to Change Proceed to Checkout
Button Text in WooCommerce?
Most Useful PHP Array Functions
Name * Email * Website
How to Add Watermark to Image Using
PHP?


Do you know what is what is a watermark and how you can protect your
images by adding watermark on them using PHP programmatically?
NO?
Don’t worry!
In this tutorial, we will learn how to add a watermark on the image using PHP
and what it is actually.
So let’s get started.
Table of Contents
1
What is a Watermark?
2
Add Text Watermark to Image Using PHP
3
Add Image Watermark to Image Using PHP
4
Some guidelines:
What is a Watermark?
Suppose You are a web professional and working on an e-commerce project.
you have some images of the different products. Now you need to write
‘featured’ or ‘new’? on some products. for doing so you need to edit your images
of the product.
So you can do it using a simple PHP GD script that’s called a watermark.
You can create different types of watermarks on all of your images using PHP
script. With this PHP GD script, you can add text as a watermark and also image
as a watermark. Let’s start work with this library script.
Add Text Watermark to Image Using PHP
Here I am going to show you a way how you can dynamically put a text
message on your images of the products.
Only you need it? JPG product image file and a font file used to generate the
watermark message. Here I am using Arial font which you can also download
from google.
Below are some steps to create a watermark on an image you just need to
follow these steps:
Step 1: First of all You need to download the ‘arial.ttf’ font file and place it in
your script folder. you can download the font file from here.
Step 2: Create a new PHP file in your script folder and place the following code
in your file.
In the above code, we created a function watermarkImage() and did the
functionality for adding watermark on image inside.
The last 4 lines for holding the data to run the watermark function.

$SourcceFile: The main image file path

$DestinationFile: Output image name

$WaterMarkText: Text you want to add on the image as watermark.
And last is hitting the watermarkImage() function to create a watermark image
with text.
Step 3: If you want to change the value of the $red variable but make sure
your color will be in RGB color. And change the watermark text angle and
position where text will be shown, you can change in the imagettftext().
If you don’t want to download the image and just want to show it on the browser
then set the $DestinationFile variable blank in the if condition like if
($DestinationFile="") .
Step 4: After the change, all the required fields as per your requirements then
save the file and run it on the browser. You will see the image displaying with a
watermark text message.
Add Image Watermark to Image Using PHP
As we said above, you can also add image watermark to an image. This means,
you can add an image onto another image as a watermark. To do this you need
to use imagecopy() function.
The imagecopy() function will copy the source image onto the destination
image.
Syntax: imagecopy($destinationImage, $srcImage,
$destinatioX, $destinationY, $sourceX, $sourceY,
$sourceWidth, $sourceHeight);
Follow the below steps to add image watermark:
Step 1: Create a folder and take two images inside it. One will be main image
and second will be watermal image in PNG format.
Step 2: Now create a new PHP file and paste the following code in this file.
This script code will create a new image with watermark image. You have to
provide the images file and required parameter. The last 4 line same as I
explained in above.
Step 3: Save the file and run on the browser. You will see watermark image onto
the main image file.
That’s it!!!
Some guidelines:
As you can see watermarkImage() image function in the script above.
which takes 3 parameters ($SourceFile, $WaterMarkText, $DestinationFile) and
creates an watermarked image from the source image specified.
$SourceFile – It is the full file path to the JPG image that you are going to
watermark.
$WaterMarkText and $WaterMarkImage – It is the text message and image
that you want to use for the watermark.
$DestinationFile – It can either be blank or full file path to a new file which will
be the source file with watermark text on it.
What this function does is to read the source file, then create a new image object
(using the imagecopyresampled() function). Then using the Arial.ttf font file
and the imagettftext() function it writes the text onto the image and image onto
image. The last IF statement checks, if it should save a new watermarked file or
should just display it on the screen.
Hope you understand the code to add watermark to image using PHP GD script
library.
If you have any quetions please ask me in the comment section. I’ll respond to
you as soon as possible.
YOU MAY ALSO LIKE
ABOUT THE AUTHOR: AMAN MEHRA
Hey! I'm Aman Mehra and I'm a full-stack developer and have 5+
years of experience. I love coding and help to people with this blog.
LEAVE A REPLY
Your email address will not be published. Required fields are marked *
Comment
Save my name, email, and website in this browser for the next time I comment.
FOLLOW US
Stay updated via social channels
Get New Post By Email
Name
Your email address
RECENT POSTS
CATEGORIES
MOST VIEWED POSTS
TIPS & TRICKS
HOW TO PHP
POST COMMENT
SUBSCRIBE
Blog Categories  Tips & Tricks Contact

HOME 
PHP HOW TO ADD WATERMARK TO IMAGE USING PHP?
AMAN MEHRA
 

JULY 4, 2021 LEAVE A COMMENT

 

Tweet on Twitter Share on Facebook
ADD WATERMARK TO IMAGE
 GETIMAGESIZE()
 HOW TO USE WATERMARK

IMAGECOLORALLOCATE()
 IMAGECOPY()
 IMAGECOPYRESAMPLED()

IMAGECREATEFROMJPEG()
 IMAGECREATEFROMPNG()
 IMAGECREATETRUECOLOR()

IMAGEDESTROY()
 IMAGEJPEG()
 IMAGESX()
 IMAGESY()
 LIST()
 PHP

PHP ADD WATERMARK TO IMAGE AND SAVE
 PHP SCRIPT FOR WATERMARK

PHP WATERMARK IMAGE WITH TEXT
 WATERMARK PATTERN
 WATERMARK PHP SCRIPT

WATERMARK STYLE


 

Tweet on Twitter Share on Facebook
How to Hide Admin Bar in
WordPress?
How to Duplicate Pages OR Posts
in WordPress?
Laravel Eloquent Methods
firstOrNew firstOrCreate
updateOrCreate
How to Test Internet Speed Using
Python?
Fix WordPress Fatal Error Allowed
Memory Size Exhausted
Git
How To
JavaScript
Laravel
PHP
Python
ReactJS
WooCommerce
WordPress
WooCommerce Remove Update
Cart Button and Make it
Automatically Update.
How to Redirect to Checkout After
Add to Cart?
How to Change Price of Specific
Product and Quantity in Cart?
Upload Multiple Featured Images
in a Post OR Page
How can I Prevent SQL Injection in
PHP?
Create CSV from PHP Array
Get Current Page URL in PHP
How to Take Chrome Full Page
Screenshot Without Extension?
Check IP Address with Python
How to Detect IE Browser (Internet
Explorer or Edge) in JavaScript?
ABOUT
Your Blog Coach is the best site
for finding the solution to any
QUICK LINKS
Blog
RECENT POSTS
How to Hide Admin Bar in
WordPress?
GET IN TOUCH
Name
<?php
​
function watermarkImage ($SourceFile, $WaterMarkText, $D
list($width, $height) = getimagesize($SourceFile);
$image_p = imagecreatetruecolor($width, $height);
$image = imagecreatefromjpeg($SourceFile);
imagecopyresampled($image_p, $image, 0, 0, 0, 0, $w
$red = imagecolorallocate($image_p, 255, 0, 0);
$font = 'D:xamphtdocsphptestwatermarkarial.ttf
$font_size = 10;
imagettftext($image_p, $font_size, 40, 100, 100, $r
if ($DestinationFile) {
imagejpeg ($image_p, $DestinationFile, 100);
} else {
header('Content-Type: image/jpeg');
imagejpeg($image_p, null, 100);
};
imagedestroy($image);
imagedestroy($image_p);
}
​
$SourceFile = 'avatar.jpg';
$DestinationFile = 'avatar-watermarkk.jpg';
$WaterMarkText = 'Copyright phpJabbers.com';
watermarkImage ($SourceFile, $WaterMarkText, $Destinatio
​
?>
<?php
​
function watermarkImage ($SourceFile, $WaterMarkImage, $
$watermark = imagecreatefrompng($WaterMarkImage);
$imageURL = imagecreatefromjpeg($SourceFile);
$watermarkX = imagesx($watermark);
$watermarkY = imagesy($watermark);
imagecopy($imageURL, $watermark, imagesx($imageURL)/
if ($DestinationFile) {
imagejpeg ($imageURL, $DestinationFile, 100);
} else {
header('Content-Type: image/jpeg');
imagejpeg($imageURL, null, 100);
}
imagedestroy($imageURL);
}
​
$SourceFile = 'avatar.jpg';
$DestinationFile = 'avatar-watermarkk.jpg';
$WaterMarkImage = 'watermark.png';
watermarkImage ($SourceFile, $WaterMarkImage, $Destinati
​
?>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
© 2020 Your Blog Coach Privacy Policy
 Terms and Conditions
 Sitemap
issue related to coding and learn
more cool stuff and tricks.
Categories
Contact
About
How to Duplicate Pages OR Posts
in WordPress?
Laravel Eloquent Methods
firstOrNew firstOrCreate
updateOrCreate
Your email address
SUBSCRIBE

More Related Content

PDF
How to Create a Custom WordPress Plugin
PPTX
Part 4 Introduction to Gui with tkinter
PPT
WordPress Standardized Loop API
PDF
Deck 893ff61f-1fb8-4e15-a379-775dfdbcee77-12-53
PDF
En2308 i web b2c integration guide
PPT
Lecture 3 Javascript1
PPTX
Css, xhtml, javascript
PPTX
Sqlite3 databases
How to Create a Custom WordPress Plugin
Part 4 Introduction to Gui with tkinter
WordPress Standardized Loop API
Deck 893ff61f-1fb8-4e15-a379-775dfdbcee77-12-53
En2308 i web b2c integration guide
Lecture 3 Javascript1
Css, xhtml, javascript
Sqlite3 databases

What's hot (18)

PPT
CIS 451: Introduction to ASP.NET
ODP
Don't sh** in the Pool
PPTX
PPT
HTML 5 Overview
PPT
Eugene Andruszczenko: jQuery
PPT
PPTX
TopicHero Descriptions Tutorial
PPTX
Creating Openbravo Workspace Widgets
PPTX
Conquering Code with hjc
PPTX
Technology
PDF
Introduction to html5
PDF
Wordcamp abq cf-cpt
PPTX
BASIC HTML PRESENTATION
PDF
The Django Book chapter 4 templates (supplement)
PDF
WordCamp ABQ 2013: Making the leap from Designer to Designer/Developer
PDF
HTML Tutorial
PDF
Fewd week4 slides
PPT
CSS3 and a brief introduction to Google Maps API v3
CIS 451: Introduction to ASP.NET
Don't sh** in the Pool
HTML 5 Overview
Eugene Andruszczenko: jQuery
TopicHero Descriptions Tutorial
Creating Openbravo Workspace Widgets
Conquering Code with hjc
Technology
Introduction to html5
Wordcamp abq cf-cpt
BASIC HTML PRESENTATION
The Django Book chapter 4 templates (supplement)
WordCamp ABQ 2013: Making the leap from Designer to Designer/Developer
HTML Tutorial
Fewd week4 slides
CSS3 and a brief introduction to Google Maps API v3
Ad

Similar to How to add watermark to image using php (6)

PPTX
Drawing images
PPSX
DIWE - Using Extensions and Image Manipulation
PDF
Getting started with Imagemagick
PDF
Image manipulation in WordPress 3.5
DOC
PHP code examples
PPT
Watermarking in-imageprocessing
Drawing images
DIWE - Using Extensions and Image Manipulation
Getting started with Imagemagick
Image manipulation in WordPress 3.5
PHP code examples
Watermarking in-imageprocessing
Ad

Recently uploaded (20)

PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
Cloud computing and distributed systems.
PDF
Spectral efficient network and resource selection model in 5G networks
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPT
Teaching material agriculture food technology
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PDF
Empathic Computing: Creating Shared Understanding
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
cuic standard and advanced reporting.pdf
PDF
Assigned Numbers - 2025 - Bluetooth® Document
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
Building Integrated photovoltaic BIPV_UPV.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Dropbox Q2 2025 Financial Results & Investor Presentation
Encapsulation_ Review paper, used for researhc scholars
Chapter 3 Spatial Domain Image Processing.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
Digital-Transformation-Roadmap-for-Companies.pptx
Cloud computing and distributed systems.
Spectral efficient network and resource selection model in 5G networks
“AI and Expert System Decision Support & Business Intelligence Systems”
Per capita expenditure prediction using model stacking based on satellite ima...
Teaching material agriculture food technology
MIND Revenue Release Quarter 2 2025 Press Release
Empathic Computing: Creating Shared Understanding
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Mobile App Security Testing_ A Comprehensive Guide.pdf
cuic standard and advanced reporting.pdf
Assigned Numbers - 2025 - Bluetooth® Document
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf

How to add watermark to image using php

  • 1. How to Hide Admin Bar in WordPress? How to Duplicate Pages OR Posts in WordPress? How to Test Internet Speed Using Python? Twitter Search API Example Using PHP How to Change Proceed to Checkout Button Text in WooCommerce? Most Useful PHP Array Functions Name * Email * Website How to Add Watermark to Image Using PHP? Do you know what is what is a watermark and how you can protect your images by adding watermark on them using PHP programmatically? NO? Don’t worry! In this tutorial, we will learn how to add a watermark on the image using PHP and what it is actually. So let’s get started. Table of Contents 1 What is a Watermark? 2 Add Text Watermark to Image Using PHP 3 Add Image Watermark to Image Using PHP 4 Some guidelines: What is a Watermark? Suppose You are a web professional and working on an e-commerce project. you have some images of the different products. Now you need to write ‘featured’ or ‘new’? on some products. for doing so you need to edit your images of the product. So you can do it using a simple PHP GD script that’s called a watermark. You can create different types of watermarks on all of your images using PHP script. With this PHP GD script, you can add text as a watermark and also image as a watermark. Let’s start work with this library script. Add Text Watermark to Image Using PHP Here I am going to show you a way how you can dynamically put a text message on your images of the products. Only you need it? JPG product image file and a font file used to generate the watermark message. Here I am using Arial font which you can also download from google. Below are some steps to create a watermark on an image you just need to follow these steps: Step 1: First of all You need to download the ‘arial.ttf’ font file and place it in your script folder. you can download the font file from here. Step 2: Create a new PHP file in your script folder and place the following code in your file. In the above code, we created a function watermarkImage() and did the functionality for adding watermark on image inside. The last 4 lines for holding the data to run the watermark function. $SourcceFile: The main image file path $DestinationFile: Output image name $WaterMarkText: Text you want to add on the image as watermark. And last is hitting the watermarkImage() function to create a watermark image with text. Step 3: If you want to change the value of the $red variable but make sure your color will be in RGB color. And change the watermark text angle and position where text will be shown, you can change in the imagettftext(). If you don’t want to download the image and just want to show it on the browser then set the $DestinationFile variable blank in the if condition like if ($DestinationFile="") . Step 4: After the change, all the required fields as per your requirements then save the file and run it on the browser. You will see the image displaying with a watermark text message. Add Image Watermark to Image Using PHP As we said above, you can also add image watermark to an image. This means, you can add an image onto another image as a watermark. To do this you need to use imagecopy() function. The imagecopy() function will copy the source image onto the destination image. Syntax: imagecopy($destinationImage, $srcImage, $destinatioX, $destinationY, $sourceX, $sourceY, $sourceWidth, $sourceHeight); Follow the below steps to add image watermark: Step 1: Create a folder and take two images inside it. One will be main image and second will be watermal image in PNG format. Step 2: Now create a new PHP file and paste the following code in this file. This script code will create a new image with watermark image. You have to provide the images file and required parameter. The last 4 line same as I explained in above. Step 3: Save the file and run on the browser. You will see watermark image onto the main image file. That’s it!!! Some guidelines: As you can see watermarkImage() image function in the script above. which takes 3 parameters ($SourceFile, $WaterMarkText, $DestinationFile) and creates an watermarked image from the source image specified. $SourceFile – It is the full file path to the JPG image that you are going to watermark. $WaterMarkText and $WaterMarkImage – It is the text message and image that you want to use for the watermark. $DestinationFile – It can either be blank or full file path to a new file which will be the source file with watermark text on it. What this function does is to read the source file, then create a new image object (using the imagecopyresampled() function). Then using the Arial.ttf font file and the imagettftext() function it writes the text onto the image and image onto image. The last IF statement checks, if it should save a new watermarked file or should just display it on the screen. Hope you understand the code to add watermark to image using PHP GD script library. If you have any quetions please ask me in the comment section. I’ll respond to you as soon as possible. YOU MAY ALSO LIKE ABOUT THE AUTHOR: AMAN MEHRA Hey! I'm Aman Mehra and I'm a full-stack developer and have 5+ years of experience. I love coding and help to people with this blog. LEAVE A REPLY Your email address will not be published. Required fields are marked * Comment Save my name, email, and website in this browser for the next time I comment. FOLLOW US Stay updated via social channels Get New Post By Email Name Your email address RECENT POSTS CATEGORIES MOST VIEWED POSTS TIPS & TRICKS HOW TO PHP POST COMMENT SUBSCRIBE Blog Categories  Tips & Tricks Contact  HOME PHP HOW TO ADD WATERMARK TO IMAGE USING PHP? AMAN MEHRA JULY 4, 2021 LEAVE A COMMENT Tweet on Twitter Share on Facebook ADD WATERMARK TO IMAGE  GETIMAGESIZE()  HOW TO USE WATERMARK  IMAGECOLORALLOCATE()  IMAGECOPY()  IMAGECOPYRESAMPLED()  IMAGECREATEFROMJPEG()  IMAGECREATEFROMPNG()  IMAGECREATETRUECOLOR()  IMAGEDESTROY()  IMAGEJPEG()  IMAGESX()  IMAGESY()  LIST()  PHP  PHP ADD WATERMARK TO IMAGE AND SAVE  PHP SCRIPT FOR WATERMARK  PHP WATERMARK IMAGE WITH TEXT  WATERMARK PATTERN  WATERMARK PHP SCRIPT  WATERMARK STYLE  Tweet on Twitter Share on Facebook How to Hide Admin Bar in WordPress? How to Duplicate Pages OR Posts in WordPress? Laravel Eloquent Methods firstOrNew firstOrCreate updateOrCreate How to Test Internet Speed Using Python? Fix WordPress Fatal Error Allowed Memory Size Exhausted Git How To JavaScript Laravel PHP Python ReactJS WooCommerce WordPress WooCommerce Remove Update Cart Button and Make it Automatically Update. How to Redirect to Checkout After Add to Cart? How to Change Price of Specific Product and Quantity in Cart? Upload Multiple Featured Images in a Post OR Page How can I Prevent SQL Injection in PHP? Create CSV from PHP Array Get Current Page URL in PHP How to Take Chrome Full Page Screenshot Without Extension? Check IP Address with Python How to Detect IE Browser (Internet Explorer or Edge) in JavaScript? ABOUT Your Blog Coach is the best site for finding the solution to any QUICK LINKS Blog RECENT POSTS How to Hide Admin Bar in WordPress? GET IN TOUCH Name <?php ​ function watermarkImage ($SourceFile, $WaterMarkText, $D list($width, $height) = getimagesize($SourceFile); $image_p = imagecreatetruecolor($width, $height); $image = imagecreatefromjpeg($SourceFile); imagecopyresampled($image_p, $image, 0, 0, 0, 0, $w $red = imagecolorallocate($image_p, 255, 0, 0); $font = 'D:xamphtdocsphptestwatermarkarial.ttf $font_size = 10; imagettftext($image_p, $font_size, 40, 100, 100, $r if ($DestinationFile) { imagejpeg ($image_p, $DestinationFile, 100); } else { header('Content-Type: image/jpeg'); imagejpeg($image_p, null, 100); }; imagedestroy($image); imagedestroy($image_p); } ​ $SourceFile = 'avatar.jpg'; $DestinationFile = 'avatar-watermarkk.jpg'; $WaterMarkText = 'Copyright phpJabbers.com'; watermarkImage ($SourceFile, $WaterMarkText, $Destinatio ​ ?> <?php ​ function watermarkImage ($SourceFile, $WaterMarkImage, $ $watermark = imagecreatefrompng($WaterMarkImage); $imageURL = imagecreatefromjpeg($SourceFile); $watermarkX = imagesx($watermark); $watermarkY = imagesy($watermark); imagecopy($imageURL, $watermark, imagesx($imageURL)/ if ($DestinationFile) { imagejpeg ($imageURL, $DestinationFile, 100); } else { header('Content-Type: image/jpeg'); imagejpeg($imageURL, null, 100); } imagedestroy($imageURL); } ​ $SourceFile = 'avatar.jpg'; $DestinationFile = 'avatar-watermarkk.jpg'; $WaterMarkImage = 'watermark.png'; watermarkImage ($SourceFile, $WaterMarkImage, $Destinati ​ ?> 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
  • 2. © 2020 Your Blog Coach Privacy Policy Terms and Conditions Sitemap issue related to coding and learn more cool stuff and tricks. Categories Contact About How to Duplicate Pages OR Posts in WordPress? Laravel Eloquent Methods firstOrNew firstOrCreate updateOrCreate Your email address SUBSCRIBE