htaccess以及水印 [英] Htaccess and watermark

查看:264
本文介绍了htaccess以及水印的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否有可能以保护那些从外部加载通过使用添加水印我的主人的图像的.htaccess

I want to know if it is possible to protect images in my host that are loaded from outside by adding a watermark using .htaccess?

也就是说,如果其他网站使用我的形象的网址 http://example.com/1.jpg 在自己的网站一个img标签。

That is, if another site uses my image URL http://example.com/1.jpg in a img tag in their own websites.

该计划是当外国请求到达我的主人,我添加水印并将其发送给浏览国外网站的用户。

The plan is the when a foreign request comes to my host, I add a watermark to it and send it to the user browsing the foreign site.

推荐答案

你基本上想要做的,就是先从本教程:

What you basically want to do, is start with this tutorial:

http://www.alistapart.com/articles/hotlinking/

此向您介绍如何重定向来自外部网站的PHP页面图像。然后,您可以使用PHP页面水印图像,像这样的东西:

This shows you how to redirect images that come from external sites to a PHP page. Then, you can use that PHP page to watermark your image, with something like this:

<?php
header('content-type: image/jpeg');
$watermark = imagecreatefrompng('watermark.png');
$watermark_width = imagesx($watermark);
$watermark_height = imagesy($watermark);
$image = imagecreatetruecolor($watermark_width, $watermark_height);
$image = imagecreatefromjpeg($_GET['pic']);
$size = getimagesize($_GET['pic']);
$dest_x = $size[0] - $watermark_width - 5;
$dest_y = $size[1] - $watermark_height - 5;
imagecopymerge($image, $watermark, $dest_x, $dest_y, 0, 0, $watermark_width, $watermark_height, 100);
imagejpeg($image);
imagedestroy($image);
imagedestroy($watermark);
?>

这篇关于htaccess以及水印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆