Code for .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://([^.]+\.)?domain\.com/ [NC]
RewriteCond %{HTTP_USER_AGENT} !(googlebot-image|msnbot|psbot|yahoo-mmcrawler) [NC]
RewriteRule (^.*\.(bmp|gif|jpe?g|png)$) /watermark.php?src=$1 [L]
</IfModule>
Code for watermark.php PHP file:
<?php
header('content-type: image/jpeg');
$image = imagecreatefromjpeg($_GET['src']);
$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$dest_x = imagesx($image) - $watermark_width;
$dest_y = imagesy($image) - $watermark_height;
imagecopymerge($image, $watermark, $dest_x - 5, 5, 0, 0, $watermark_width, $watermark_height, 80);
imagejpeg($image, NULL, 85);
imagedestroy($image);
imagedestroy($watermark);
?>
Hello, thanks for the advice.
BUT .png images don't work for me
Writes - The image cannot be displayed because it contains errors.
What is the reason? Thank you!