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

What's hot

CIS 451: Introduction to ASP.NET
CIS 451: Introduction to ASP.NETCIS 451: Introduction to ASP.NET
CIS 451: Introduction to ASP.NET
webhostingguy
 
Don't sh** in the Pool
Don't sh** in the PoolDon't sh** in the Pool
Don't sh** in the Pool
Chris Jean
 
django
djangodjango
HTML 5 Overview
HTML 5 OverviewHTML 5 Overview
HTML 5 Overview
Offir Ariel
 
Eugene Andruszczenko: jQuery
Eugene Andruszczenko: jQueryEugene Andruszczenko: jQuery
Eugene Andruszczenko: jQuery
Refresh Events
 
Php
PhpPhp
Dopp xhtml tutorial
Dopp xhtml tutorialDopp xhtml tutorial
Dopp xhtml tutorial
Tarsem Dadhwal
 
TopicHero Descriptions Tutorial
TopicHero Descriptions TutorialTopicHero Descriptions Tutorial
TopicHero Descriptions Tutorial
Justin Coven, Ph.D.
 
Creating Openbravo Workspace Widgets
Creating Openbravo Workspace WidgetsCreating Openbravo Workspace Widgets
Creating Openbravo Workspace Widgets
Rob Goris
 
Conquering Code with hjc
Conquering Code with hjcConquering Code with hjc
Conquering Code with hjc
hjc
 
Technology
TechnologyTechnology
Technology
naylovesu
 
Introduction to html5
Introduction to html5Introduction to html5
Introduction to html5
kolev-prp
 
Wordcamp abq cf-cpt
Wordcamp abq cf-cptWordcamp abq cf-cpt
Wordcamp abq cf-cpt
my easel
 
BASIC HTML PRESENTATION
BASIC HTML PRESENTATIONBASIC HTML PRESENTATION
BASIC HTML PRESENTATION
THABISO BALOYI
 
The Django Book chapter 4 templates (supplement)
The Django Book chapter 4 templates (supplement)The Django Book chapter 4 templates (supplement)
The Django Book chapter 4 templates (supplement)
Vincent Chien
 
WordCamp ABQ 2013: Making the leap from Designer to Designer/Developer
WordCamp ABQ 2013: Making the leap from Designer to Designer/DeveloperWordCamp ABQ 2013: Making the leap from Designer to Designer/Developer
WordCamp ABQ 2013: Making the leap from Designer to Designer/Developer
my easel
 
HTML Tutorial
HTML TutorialHTML Tutorial
HTML Tutorial
Milecia McGregor
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
William Myers
 
CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3 CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3
Jeffrey Barke
 

What's hot (19)

CIS 451: Introduction to ASP.NET
CIS 451: Introduction to ASP.NETCIS 451: Introduction to ASP.NET
CIS 451: Introduction to ASP.NET
 
Don't sh** in the Pool
Don't sh** in the PoolDon't sh** in the Pool
Don't sh** in the Pool
 
django
djangodjango
django
 
HTML 5 Overview
HTML 5 OverviewHTML 5 Overview
HTML 5 Overview
 
Eugene Andruszczenko: jQuery
Eugene Andruszczenko: jQueryEugene Andruszczenko: jQuery
Eugene Andruszczenko: jQuery
 
Php
PhpPhp
Php
 
Dopp xhtml tutorial
Dopp xhtml tutorialDopp xhtml tutorial
Dopp xhtml tutorial
 
TopicHero Descriptions Tutorial
TopicHero Descriptions TutorialTopicHero Descriptions Tutorial
TopicHero Descriptions Tutorial
 
Creating Openbravo Workspace Widgets
Creating Openbravo Workspace WidgetsCreating Openbravo Workspace Widgets
Creating Openbravo Workspace Widgets
 
Conquering Code with hjc
Conquering Code with hjcConquering Code with hjc
Conquering Code with hjc
 
Technology
TechnologyTechnology
Technology
 
Introduction to html5
Introduction to html5Introduction to html5
Introduction to html5
 
Wordcamp abq cf-cpt
Wordcamp abq cf-cptWordcamp abq cf-cpt
Wordcamp abq cf-cpt
 
BASIC HTML PRESENTATION
BASIC HTML PRESENTATIONBASIC HTML PRESENTATION
BASIC HTML PRESENTATION
 
The Django Book chapter 4 templates (supplement)
The Django Book chapter 4 templates (supplement)The Django Book chapter 4 templates (supplement)
The Django Book chapter 4 templates (supplement)
 
WordCamp ABQ 2013: Making the leap from Designer to Designer/Developer
WordCamp ABQ 2013: Making the leap from Designer to Designer/DeveloperWordCamp ABQ 2013: Making the leap from Designer to Designer/Developer
WordCamp ABQ 2013: Making the leap from Designer to Designer/Developer
 
HTML Tutorial
HTML TutorialHTML Tutorial
HTML Tutorial
 
Fewd week4 slides
Fewd week4 slidesFewd week4 slides
Fewd week4 slides
 
CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3 CSS3 and a brief introduction to Google Maps API v3
CSS3 and a brief introduction to Google Maps API v3
 

Similar to How to add watermark to image using php

Build Your Own Instagram Filters
Build Your Own Instagram FiltersBuild Your Own Instagram Filters
Build Your Own Instagram Filters
TJ Stalcup
 
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to DevelopmentWordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
Evan Mullins
 
Machine learning in php Using PHP-ML
Machine learning in php Using PHP-MLMachine learning in php Using PHP-ML
Machine learning in php Using PHP-ML
Agbagbara Omokhoa
 
Rails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 IssueRails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 Issue
Sagar Arlekar
 
Jumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin ProgrammingJumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin Programming
Dougal Campbell
 
Progressive Web Application by Citytech
Progressive Web Application by CitytechProgressive Web Application by Citytech
Progressive Web Application by Citytech
Ritwik Das
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
Mainak Goswami
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
Steve Mortiboy
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
Aiman Hud
 
Php mysql-training online-by_php2ranjan
Php mysql-training online-by_php2ranjanPhp mysql-training online-by_php2ranjan
Php mysql-training online-by_php2ranjan
php2ranjan
 
php training in hyderabad
php training in hyderabadphp training in hyderabad
php training in hyderabad
php2ranjan
 
How to create your own WordPress plugin
How to create your own WordPress pluginHow to create your own WordPress plugin
How to create your own WordPress plugin
John Tighe
 
How to build and deploy app on Replit
How to build and deploy app on ReplitHow to build and deploy app on Replit
How to build and deploy app on Replit
matiasfund
 
WordPress Theme Design - Rich Media Institute Workshop
WordPress Theme Design - Rich Media Institute WorkshopWordPress Theme Design - Rich Media Institute Workshop
WordPress Theme Design - Rich Media Institute Workshop
Brendan Sera-Shriar
 
INTRODUCTIONS OF HTML
INTRODUCTIONS OF HTMLINTRODUCTIONS OF HTML
INTRODUCTIONS OF HTML
SURYANARAYANBISWAL1
 
Plugin development demystified 2017
Plugin development demystified 2017Plugin development demystified 2017
Plugin development demystified 2017
ylefebvre
 
Build the Perfect WordPress Website
Build the Perfect WordPress WebsiteBuild the Perfect WordPress Website
Build the Perfect WordPress Website
Sinergia Labs
 
Wordpress as a framework
Wordpress as a frameworkWordpress as a framework
Wordpress as a framework
Aggelos Synadakis
 
How to Use PHP in HTML.pdf
How to Use PHP in HTML.pdfHow to Use PHP in HTML.pdf
How to Use PHP in HTML.pdf
CIOWomenMagazine
 
Article 01 What Is Php
Article 01   What Is PhpArticle 01   What Is Php
Article 01 What Is Php
drperl
 

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

Build Your Own Instagram Filters
Build Your Own Instagram FiltersBuild Your Own Instagram Filters
Build Your Own Instagram Filters
 
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to DevelopmentWordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
WordCamp Greenville 2018 - Beware the Dark Side, or an Intro to Development
 
Machine learning in php Using PHP-ML
Machine learning in php Using PHP-MLMachine learning in php Using PHP-ML
Machine learning in php Using PHP-ML
 
Rails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 IssueRails Plugins - Linux For You, March 2011 Issue
Rails Plugins - Linux For You, March 2011 Issue
 
Jumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin ProgrammingJumping Into WordPress Plugin Programming
Jumping Into WordPress Plugin Programming
 
Progressive Web Application by Citytech
Progressive Web Application by CitytechProgressive Web Application by Citytech
Progressive Web Application by Citytech
 
Step by step guide for creating wordpress plugin
Step by step guide for creating wordpress pluginStep by step guide for creating wordpress plugin
Step by step guide for creating wordpress plugin
 
Getting started with WordPress development
Getting started with WordPress developmentGetting started with WordPress development
Getting started with WordPress development
 
POLITEKNIK MALAYSIA
POLITEKNIK MALAYSIAPOLITEKNIK MALAYSIA
POLITEKNIK MALAYSIA
 
Php mysql-training online-by_php2ranjan
Php mysql-training online-by_php2ranjanPhp mysql-training online-by_php2ranjan
Php mysql-training online-by_php2ranjan
 
php training in hyderabad
php training in hyderabadphp training in hyderabad
php training in hyderabad
 
How to create your own WordPress plugin
How to create your own WordPress pluginHow to create your own WordPress plugin
How to create your own WordPress plugin
 
How to build and deploy app on Replit
How to build and deploy app on ReplitHow to build and deploy app on Replit
How to build and deploy app on Replit
 
WordPress Theme Design - Rich Media Institute Workshop
WordPress Theme Design - Rich Media Institute WorkshopWordPress Theme Design - Rich Media Institute Workshop
WordPress Theme Design - Rich Media Institute Workshop
 
INTRODUCTIONS OF HTML
INTRODUCTIONS OF HTMLINTRODUCTIONS OF HTML
INTRODUCTIONS OF HTML
 
Plugin development demystified 2017
Plugin development demystified 2017Plugin development demystified 2017
Plugin development demystified 2017
 
Build the Perfect WordPress Website
Build the Perfect WordPress WebsiteBuild the Perfect WordPress Website
Build the Perfect WordPress Website
 
Wordpress as a framework
Wordpress as a frameworkWordpress as a framework
Wordpress as a framework
 
How to Use PHP in HTML.pdf
How to Use PHP in HTML.pdfHow to Use PHP in HTML.pdf
How to Use PHP in HTML.pdf
 
Article 01 What Is Php
Article 01   What Is PhpArticle 01   What Is Php
Article 01 What Is Php
 

Recently uploaded

GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
Tomaz Bratanic
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
Matthew Sinclair
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
Pixlogix Infotech
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
tolgahangng
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
Kari Kakkonen
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
akankshawande
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
Mariano Tinti
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
FODUU
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
danishmna97
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
Zilliz
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
Zilliz
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
kumardaparthi1024
 

Recently uploaded (20)

GraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracyGraphRAG for Life Science to increase LLM accuracy
GraphRAG for Life Science to increase LLM accuracy
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
20240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 202420240605 QFM017 Machine Intelligence Reading List May 2024
20240605 QFM017 Machine Intelligence Reading List May 2024
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Best 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERPBest 20 SEO Techniques To Improve Website Visibility In SERP
Best 20 SEO Techniques To Improve Website Visibility In SERP
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Serial Arm Control in Real Time Presentation
Serial Arm Control in Real Time PresentationSerial Arm Control in Real Time Presentation
Serial Arm Control in Real Time Presentation
 
Climate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing DaysClimate Impact of Software Testing at Nordic Testing Days
Climate Impact of Software Testing at Nordic Testing Days
 
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development ProvidersYour One-Stop Shop for Python Success: Top 10 US Python Development Providers
Your One-Stop Shop for Python Success: Top 10 US Python Development Providers
 
Mariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceXMariano G Tinti - Decoding SpaceX
Mariano G Tinti - Decoding SpaceX
 
Things to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUUThings to Consider When Choosing a Website Developer for your Website | FODUU
Things to Consider When Choosing a Website Developer for your Website | FODUU
 
How to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptxHow to Get CNIC Information System with Paksim Ga.pptx
How to Get CNIC Information System with Paksim Ga.pptx
 
Fueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte WebinarFueling AI with Great Data with Airbyte Webinar
Fueling AI with Great Data with Airbyte Webinar
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
TrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy SurveyTrustArc Webinar - 2024 Global Privacy Survey
TrustArc Webinar - 2024 Global Privacy Survey
 
Generating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and MilvusGenerating privacy-protected synthetic data using Secludy and Milvus
Generating privacy-protected synthetic data using Secludy and Milvus
 
GenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizationsGenAI Pilot Implementation in the organizations
GenAI Pilot Implementation in the organizations
 

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