2011年3月1日星期二

Gonzalo Ayuso's Blog: Watermarks in our images with PHP and mod_rewrite


Gonzalo Ayuso has a new tutorial posted to his site today showing how to use mod_rewrite and a little bit of PHP magic to watermark images without having to apply it to each one manually.



he idea is simple. Instead of opening directly the image, we are going to open a PHP script. This PHP script will open the original image file with imagecreatefromjpeg, add the footer and flush the new image to the browser with the properly headers.


Since it would be a lot of trouble (especially on a larger site) to have to rewrite all of the <img> tags to point to this new PHP script for adding the watermark, he opts for the .htaccess instead. It catches and rewrites the request to the "watermark.php" file which pulls in that image, watermarks it and pushes the result back out.

没有评论:

发表评论