This is happen 3 days ago when my friend asking for converting him .htaccess into lighttpd rewrite rules format. After conversion done he wanted to share this script to everyone. If you’re professional Fotographer or just blogger, you may wanted to copyright all your photos/images. Even we know, sometimes people like to share for having fun…. but some people need a copyright to protected his original works before someone copy it. If you’re doing this manually it will take a long time and of course you will bored before this done. In short time we can make a simple watermark to protected our images.
Requirements:
- Apache with mod_rewrite / lighttpd (just convert rewrite rules, it should work)
- PHP with GD library (check in your phpconfig or asking your webhosting)
Step one.
Prepare one images that you should used as watermark. This images should be in .PNG format, you can created one using photoshop software to make transparant effect.
Step two.
Make new or open your .htaccess files and write down this code inside it:
RewriteEngine On
RewriteRule ^(.+)\.jpg$ wrapper.php?image=$1\.jpg [L]
RewriteRule ^(.+)\.gif$ wrapper.php?image=$1\.gif [L]
RewriteRule ^(.+)\.png$ wrapper.php?image=$1\.png [L]
RewriteRule ^(.+)\.bmp$ wrapper.php?image=$1\.bmp [L]
For Lighttpd users try to using this conversion, if you meet any problem just following your path and symbol :
url.rewrite-once = (
“^\(.*).jpg” => “/wrapper.php?image=$1.jpg”,
“^\(.*).gif” => “/wrapper.php?image=$1.gif”,
“^\(.*).png” => “/wrapper.php?image=$1.png”,
“^\(.*).bmp” => “/wrapper.php?image=$1.bmp”
)
Step three.
Create wrapper.php files and put code below inside it:
<?php
$watermark = “watermark.png”;
$image = $_GET["image"];
if (empty($image)) die();
if (!file_exists($image)) {
header(“404 Not Found”);
echo “File Not Found.”; die();
}
$outputType = getFileType($image);
watermark($image, $watermark, $outputType);
/**
Outputs the image $source with $watermark in the lower right corner.
@param $source the source image
@param $watermark the watermark to apply
@param $outputType the type to output as (png, jpg, gif, etc.)
defaults to the image type of $source if left blank
*/
function watermark($source, $watermark, $outputType=”") {
$sourceType = getFileType($source);
$watermarkType = getFileType($watermark);
if (empty($outputType)) $outputType = $sourceType;
if ($outputType == “gif”) $outputType = “png”;
header(“Content-type:image/$outputType”);
$createSource = “ImageCreateFrom”.strtoupper($sourceType);
$showImage = “Image”.strtoupper($outputType);
$createWatermark = “ImageCreateFrom”.strtoupper($watermarkType);
// Load original and watermark to memory
$output = $createSource($source);
$logo = $createWatermark($watermark);
ImageAlphaBlending($output, true);
// Find proper coordinates so watermark will be in the lower right corner
$x = ImageSX($output) – ImageSX($logo);
$y = ImageSY($output) – ImageSY($logo);
// Display
ImageCopy($output, $logo, $x, $y, 0, 0, ImageSX($logo), ImageSY($logo));
$showImage($output);
// Purge
ImageDestroy($output);
ImageDestroy($logo);
}
function getFileType($string) {
$type = strtolower(eregi_replace(“^(.*)\.”,”",$string));
if ($type == “jpg”) $type = “jpeg”;
return $type;
}
Or you can download in here.
Step Fourth.
Upload all of this files into your public_html folder (please note, all your images files will get affected, if you’re in shared hosting upload this 3 files into your root domain folder) watermark should work even you embed this images into .html I already try in this blog, it works watermark all direct images or embeding images in .html anyway I don’t like because it’s affected my other images in templates so I remove it. This will be nice script for wallpapers/photos website.
Done, Have a nice day!
SIMILAR POST :
- SEO: URL Rewrite for 4images
- Stop bandwith thief using rewrite rules on .htaccess file
- Stupid story after 3 days starting my hosting business
- How to: Created XML Sitemap Using PHP
Incoming search terms:
- php watermark imagealphablending
- watermark with php
- php watermark conversion
- embedding watermarks on uploaded pictures
- how to watermark a script
- watermark htaccess
- php watermark
- php5 watermark
- auto watermark in blogger
- php watermark function
- php watermark in blogger
- make copyright png
- php watermark picture
- php script watermark text
- wordpress watermark htaccess
- rewriterule ^( )\ jpg$ wrapper php?image=$1\ jpg [l]
- wordpress png auto watermark
- watermark wordpress htaccess
- watermark php rewrite url
- watermark php
- watermark image wordpress htaccess
- watermark image php script
- watermark for bmp files using php and htaccess
- watermark 4images automate images
- php remove watermark
- php imagecopy for a watermark
- php gd2 automatic watermark
- blogger watermark coding
- automatic watermark in blogger
- auto watermarking image in blogger
- apache watermark htaccess
- adding a watermark to wrapper in wordpress
- add watermark php bottom
- add png watermark to wordpress
- add copyright to image php htaccess
- create a watermark for blogger
- create watermark png website
- deadlock in bluehost web server
- php convert watermark bottom right
- php auto creat watermark
- php add watermark apache
- php add copyright logo to image
- php 5 watermark
- imagecopy php watermark
- gifs copyright symbol
- gd copyrights sigmbol
- add copyright photo php
If you're new here, you may want to subscribe to my RSS feed. You may copy or publish this article to your blog or other site as long you give credit link back to this site article. Thanks for visiting my blog!






Did you know?
Tag cloud
Blogs Statistic
Subscribe my feed

October 18th, 2009 at 5:22 PM
Why money factor is given much important in Indian elections?
November 5th, 2009 at 4:04 AM
thank you for the information
March 24th, 2010 at 5:21 AM
Excellent code. Perhaps too slow when you have tons of pictures (prefer creating thumbs), but very interesting. Thanks.
August 23rd, 2011 at 9:19 PM
Great blog right here! Additionally your website rather a lot up very fast! What host are you the use of? Can I get your associate hyperlink for your host? I wish my website loaded up as fast as yours lol.