Results 1 to 1 of 1
-
1st Aug 2009, 07:02 PM #1OPMember
[Tip/Trick] PHP Auto Image Watermarking
If you’ve ever wanted to watermark images on your website, this neat script will be just what you’re looking for.
The watermark image is held in a separate file, rather than having to actually edit each image with your watermark, save and upload, this script will serve the watermark to the user on the image as and when its requested.
Warez-DnB PNG
I like this approach to watermarking because no only is it much easier than editing each picture individually it also means with FTP access you still have an original image intact without the watermark. Only users connecting via HTTP will see the watermarked version.
This also allows for ultimate flexibility, if for whatever reason you decide to change the site logo, its as simple as replacing one image file and every image hosted will have the new watermark.
Save this simple PHP script below as watermark.php
Code:<?php $path = $_SERVER['DOCUMENT_ROOT'].$_SERVER['REQUEST_URI']; $image = imagecreatefromstring(file_get_contents($path)); $w = imagesx($image); $h = imagesy($image); $watermark = imagecreatefrompng('watermark.png'); $ww = imagesx($watermark); $wh = imagesy($watermark); imagecopy($image, $watermark, $w-$ww, $h-$wh, 0, 0, $ww, $wh); eregi('\.(gif|jpeg|jpg|png)$',$path,$regs); switch( $regs[1] ) { case 'gif': header('Content-type: image/gif'); imagegif($image); break; case 'jpg': case 'jpeg': header('Content-type: image/jpeg'); imagejpeg($image); break; case 'png': header('Content-type: image/png'); imagepng($image); break; } exit(); ?>
The final step is an edit to the .htaccess file (or to make a new one in the directory images are to be served from) and add the following.
Code:RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f RewriteRule \.(gif|jpeg|jpg|png)$ watermark.php [QSA,NC]
/images/watermark.php
/images/watermark.png
/images/.htaccess
Now start uploading some images and everything should be working
Examples
Before
After
EnjoyJuo Reviewed by Juo on . [Tip/Trick] PHP Auto Image Watermarking If you’ve ever wanted to watermark images on your website, this neat script will be just what you’re looking for. The watermark image is held in a separate file, rather than having to actually edit each image with your watermark, save and upload, this script will serve the watermark to the user on the image as and when its requested. http://www.besthostingforums.com/images/cdn/besthostingforums.com/2009/08/1.png Warez-DnB PNG I like this approach to watermarking because no only is it Rating: 5Safety First, then Teamwork
Sponsored Links
Thread Information
Users Browsing this Thread
There are currently 1 users browsing this thread. (0 members and 1 guests)
Similar Threads
-
Online Image Watermarking tool (can watermakr a text or Logo)
By soum111 in forum Useful SitesReplies: 4Last Post: 23rd Jul 2012, 02:57 PM -
Image auto upload help.
By Medow7 in forum Web Development AreaReplies: 2Last Post: 2nd Jul 2012, 10:40 PM -
Image Watermarking scrit
By torrfriend in forum Webmaster DiscussionReplies: 6Last Post: 6th Apr 2012, 03:42 PM -
[MyBB] Auto Image resize
By webydiploma in forum Web Application/Script SupportReplies: 3Last Post: 25th Jun 2011, 10:49 PM -
[vb][phpbb3] Image Revenue, Watermarking, hotlink protection and thumbnail mod
By SplitIce in forum Webmaster ResourcesReplies: 21Last Post: 1st Aug 2009, 12:16 PM
themaPoster - post to forums and...
Version 5.19 released. Open older version (or...