Use Apache's .htaccess, PHP makes Wrapper to give the picture plus watermark first in the directory of the watermark picture, such as / var / www / html / pic directory, write a .htacess file
AddHandler watermarked .jpgAddHandler watermarked .jpegAddHandler watermarked .gifAddHandler watermarked .pngAction watermarked /watermark/wrapper.php so all jpg / gif / png file request forward to /watermark/wrapper.php. Due to the use of AddHandle, you need an ALOWOVERRIDE of the corresponding directory in the Apache configuration file httpd.conf, allowing FileInfo, for example
Options Indexes FollowSymlinks
ALLOWOVERRIDE FILEINFO
ORDER ALOW, DENY
ALLOW FROM ALL
Directory> Create a Watermark directory under / var / www / html, write wrapper.php, the content is as follows
php $ Watermark = "watermark.png"; $ image = $ _server ["path_translated"]; if (Empty) Die (); if (! File_exists ($ image)) {header ("404 not "); Echo" File Not Found. "; Die ();} $ OUTPUTTYPE = Getfiletype ($ Image); Watermark ($ Image, $ Watermark, $ OUTPUTTYPE); / * Outputs The Image $ SOTH $ 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"; // okay to remove after july 2004 header ("content-type: image / $ outputtype"); // We're Only Looking At the File Name NOT THE DIRECTORY $ filename = basename ($ source); // Match dots "." Preg_match_all ("/( (. )/ (($ dots); // We Only Care About Match # 1 $ dots = $ dots [1]; if ($ DOTS)> 1) {// More Than One Dot, So Don't do watermarking $ fp = fopen ($ source, "rb"); $ contents = fread ($ fp, filesis); fclose ($ fp); echo $ contents;} else {// Continue with watermarking // Derive function names $ 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 ($ logo) - ImageSx ($ logo); $ y = imagesy ($ loc) - ImageeSy ($ logo); // Display ImageCopy ($ OTPUT, $ LOGO, $ x, $ y, 0, 0, imagesx ($ logo), Imageesy ($ logo); $ showimage ($ output); // purge imagedestroy ($ output); imagedestroy;}} function getfiletype $ String) {$ TYPE = STRTOLOWER (EREGI_REPLACE ("^ (", ", $ string)); if ($ type ==" jpg ") $ type =" jpeg "; returnome;} ?> To add the picture Watermark.png is also in this directory, you can also in other directories, but you need to modify this variable. Then use the browser to access a picture under the PIC. Take a look at the watermark. :), the default is to add this PHP file to other ways to change this PHP file.
Thus, there is no watermark, just add watermarking when you are requested, and some can be further determined in wrapper.php, such as judging HTTP Referer (PHP variable is $ _server ["http_referer"]) See if the request comes from This server.
Reference connection: http://www.webpronews.com/webdevelopment/basicdevelopment/wpn-37-20040429htaccessWrapPerswithPhp.html
This also tells the use .htaccess and PHP to add head / tail files, what is output before the feed of personal homepage services should be implemented in a similar technology.