note 110128 deleted from function.imagecopymerge by googleguy
| From: | googleguy@php.net | Date: | Sat, 22 Sep 2012 23:47:31 +0000 |
| Subject: | note 110128 deleted from function.imagecopymerge by googleguy | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-190964@lists.php.net to get a copy of this message | ||
Note Submitter: mikech at livinginthepast-audioweb dot co dot uk
----
(Part #1, watermarking 'X' number of images, by php replacing jpg files [see also part
#2])
Have to say that the information people put on here is excellent. So by borrowing bits and pieces
from various examples from this page, I was able to add a watermark to any number of my pictures on
site and which is done 'on the fly', i.e. as the picture is requested by a browser.
Here's how I did it:
Assume 'images' folder is at /home/mydomain/public_html/images
So:
/images/source is a sub-folder where the REAL pictures are stored.
/images/source/myphoto.jpg
^ is the REAL image file.
/images/myphoto.jpg
^ IS NOT an image file, but a short bit of PHP code with the JPG extension!
/images/.htaccess
To make this work, the system has to be told to parse this .jpg as PHP code. Thus .htaccess
contains:
<Files .htaccess>
order allow,deny
deny from all
</Files>
<FilesMatch 'myphoto.jpg'>
AddHandler application/x-httpd-php5 .jpg
</FilesMatch>
^ The exact syntax depends on how your web site works, I have to do it this way because mine's
running Apache 2.2 with 'PHP as CGI' (you can find out what yours is through the
site's control panel etc. and looking up how to do it on the web like I did).
/images/overlay.php
^ The 'engine' that does the watermarking. As there are lots of the php mascarading as jpg
files this keeps the total bytes storage down.
/images/watermark.png
^ The watermark. This is 24-bit with alpha channels (by creating a suitable mask with Paint Shop
Pro) so it has 'variable transparency', since the logo has like a gradient tinted
drop-shadow (and I won't go into how long it took me to make that work!)
/images/myphoto.jpg ~
<?php
/* Redirect to a different page in the current directory that was requested */
$uri = trim($_SERVER['PHP_SELF'], '/\\');
require_once( 'overlay.php' );
exit;
?>
^ The code gets its own file name then passes it onto the overlay. (Part #2 elsewhere)