note 110128 added to function.imagecopymerge
| From: | mikech at livinginthepast-audioweb dot co dot uk | Date: | Sat, 22 Sep 2012 17:49:44 +0000 |
| Subject: | note 110128 added to function.imagecopymerge | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-190959@lists.php.net to get a copy of this message | ||
(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)
----
Server IP: 69.147.83.199
Probable Submitter: 62.56.51.123
----
Manual Page -- http://www.php.net/manual/en/function.imagecopymerge.php
Edit -- https://master.php.net/note/edit/110128
Del: integrated -- https://master.php.net/note/delete/110128/integrated
Del: useless -- https://master.php.net/note/delete/110128/useless
Del: bad code -- https://master.php.net/note/delete/110128/bad+code
Del: spam -- https://master.php.net/note/delete/110128/spam
Del: non-english -- https://master.php.net/note/delete/110128/non-english
Del: in docs -- https://master.php.net/note/delete/110128/in+docs
Del: other reasons-- https://master.php.net/note/delete/110128
Reject -- https://master.php.net/note/reject/110128
Search -- https://master.php.net/manage/user-notes.php