Home

Resources

Journal Index

News From Home

Itinerary

Photo Gallery

*NEW* Gallery

Volunteering

What's New

faq

Watermark Image PHP Script (and Discussion)


<?php
/*
=============================================================================================
Script Name: watermark.php4
Verion: 1.0
Author: Ryan Doutt
Date: April 2007
Acknowledge: Brock Ferguson - See original article at http://www.sitepoint.com/article/watermark-images-php
which this script is based.
This is a PHP scripted, watermarking system for graphics files to be used with .htaccess on
an Apache web server. It should be called as follows from within your root .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_URI} uploads(.*) [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/path/to/watermark.php4?src=$1 [NC]
To see this script in action please point your favorite browser in the general direction of
one of the following images:
http://www.1800getryan.com/uploads/certaldo/P6180228.JPG
http://www.1800getryan.com/uploads/ireland/P8230023.JPG
http://www.1800getryan.com/uploads/broumov/P5240187.JPG
This script is available for use as freeware subject to the retention of the preceding
information and acknowledgements in any copy or modification that is made to this code.
=============================================================================================
*/
header('content-type: image/jpeg');
$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatefromjpeg($_GET['src']);
$size = getimagesize($_GET['src']);
$dest_x = $size[0] - $watermark_width;
$dest_y = $size[1] - $watermark_height;
$white = imageColorAllocate ($watermark, 255, 255, 255);
imagecolortransparent($watermark,$white);
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?>

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

I also use an automated,

I also use an automated, non-destructive watermarking system that works on the fly. This current system also leverages the .htaccess file as documented in the script. For most people who do not already have a watermark, this is where you'll likely spend most of your time, as it can be a little tricky to get things to look nice. Feel free to post your thoughtful comments and questions here. In the near future I'll also be posting information on customizing "SimpleViewer". You can check out the current implementation by clicking on the *NEW* Gallery link at the top of the page. It's a customized implementation that works with non-standard directories. Something I figure would be of interest to people who have already implemented a large online photo collection.