Sharing images online as a photographer, business owner, or even a creator comes with risks of theft and unauthorized use. How then do you ensure this doesn’t happen? One simple and powerful approach is through add watermarks to image in PHP. It allows you to programmatically put your brand logo, name, or a copyright notice right on your pictures, thus securing your digital assets.
This tutorial will take you through everything you need to know in this regard. We will explain how to add simple text-based and more professional-looking image-based watermarks. By the end, you’ll have a fully working script ready to be integrated into your projects.
Why Use a PHP Image Watermark?
Before jumping into the code, let’s take a look at a few scenarios in the real world where dynamic watermarking is particularly useful:
- Photographers & Artists: Automatically sign your name or signature on each photo in your portfolio with Photographers & Artists to prove ownership.
- E-commerce Stores: Use a semi-transparent logo on all your product images to prevent competitors from using them.
- Stock Photo Websites: The watermark will appear on previews of the images; after a user licenses the image, it will no longer be there.
- Social Media Management: Drive traffic back to your site by adding your company’s social media handle or website URL to images before you share them.
How to Add a Text Watermark in PHP
Adding a text watermark is the most straightforward method. Think of it as digitally stamping a piece of text onto your image. We will use PHP’s built-in GD library, which is available on most web hosting servers. The process involves loading the original image, defining the text and its properties (like color and font), and then merging them.
Here is a simple PHP script to add watermark text:
<?php
header('Content-type: image/jpeg');
$imageFile = 'your-image.jpg';
$image = imagecreatefromjpeg($imageFile);
$textColor = imagecolorallocate($image, 255, 255, 255);
$font = 'arial.ttf';
$text = 'Copyright 2024 My Website';
imagettftext($image, 20, 0, 30, 50, $textColor, $font, $text);
imagejpeg($image);
imagedestroy($image);
?>Our script first loads your image. It then prepares the watermark by defining the text’s color, font, and content. The code then “writes” this text onto the picture before displaying the final result and clearing it from memory.
Adding an Image Logo as a PHP Watermark
For a more professional look, you can use an image, company logo or even fevicon icon, as a watermark. It’s like placing a transparent sticker on top of a photograph. For this to work best, your logo should be a PNG file with a transparent background.
Let’s take an example for adding image or logo as watermark in PHP:
<?php
header('Content-type: image/jpeg');
$imageFile = 'your-image.jpg';
$watermarkFile = 'logo.png';
$image = imagecreatefromjpeg($imageFile);
$watermark = imagecreatefrompng($watermarkFile);
$imageWidth = imagesx($image);
$imageHeight = imagesy($image);
$watermarkWidth = imagesx($watermark);
$watermarkHeight = imagesy($watermark);
$positionX = ($imageWidth - $watermarkWidth) - 20;
$positionY = ($imageHeight - $watermarkHeight) - 20;
imagecopy($image, $watermark, $positionX, $positionY, 0, 0, $watermarkWidth, $watermarkHeight);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?>Above example process is very similar to adding text. The script begins by loading both images then it gets dimension of images to calculate where to place watermark. In this example, we place it in the bottom-right corner with a 20-pixel margin. The imagecopy() function is the key here. it merges the logo onto the main image at the position we calculated. Finally, the script outputs the newly created image.
Conclusion
You now have two powerful ways to add watermark to Image using PHP script for protecting your digital images. With these scripts, you can confidently add Watermarks to Images in PHP, whether you need a simple copyright notice or a polished company logo.
Now that you’ve mastered adding watermarks, the next step is ensuring your images are perfectly sized and compressed for fast web performance. To take your skills further, check out our complete guide on how to Optimize Images in PHP with Intervention Image, which makes complex tasks like resizing and compression incredibly simple.

