Tuesday, July 23, 2024

Say NO to image theft

- Advertisement -spot_img
- Advertisement -Traffic Analysts Tool

One of many things bloggers are afraid from, is that other people can steal images from your website, I have to say that there is no way to prevent it for all, but those ideas will make it more difficult.


There are three solutions posted here : one is a PHP code and, second is a code to put in your .htaccess file and the third one is a wordpress plugin. The PHP solution is to prevent users  from using the right click button and make it difficult to download it from your blog or to find the picture link in the source code.

1- PHP code :
Use this first in your CSS file :

.image	           { position:relative; overflow:hidden; }
.pixel		{ width:1px; height:1px; position:absolute; }
#pixels .pixel {float:left; position:relative; width:1px; height:1px;}
- Advertisement -Traffic Analysts Tool

After that use this code in your pages :

// settings
$image = 'ImageName.png';

// get the image size
list($width,$height) = getimagesize($image);
$img = imagecreatefrompng($image);

// data array
$data = array('height'=>$height,'width'=>$width,'pixels'=>array());

// start the height loop
for ($y = 0; $y < $height; $y++){
	for ($x = 0; $x < $width; $x++)
                $color_index = imagecolorat($img, $x, $y);
 		$a = ($color_index & 0x7F000000) >> 24;
		$r = ($color_index >> 16) & 0xFF;
		$g = ($color_index >> 8 ) & 0xFF;
		$b = $color_index & 0xFF;
		if ($a > 0){
			$a = abs(($a / 127) - 1);
			$a = hex(round($a * 255));
		} else {
			$a = '';
		$r = hex($r);
		$g = hex($g);
		$b = hex($b);
		$data['pixels'][] = "$r$g$b$a";

// clean up

/* utility function */
function hex($v){
	$bit = dechex($v);
	if (strlen($bit) == 1) $bit = "0$bit";
	return $bit;

2- .htaccess file :

The second way is when you like to stop hotlinkers, just put those lines in your .htaccess file, Hotlink protection can save you lots of bandwidth by preventing other websites from displaying your images or pictures  :

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain1.com [NC]
RewriteCond %{HTTP_REFERER} !^http(s)?://(www\.)?yourdomain2.com [NC]
RewriteRule .(gif|jpg|jpeg|png)$  http://www.yourdomain/pic.jpg  [R,L]

The 4th line is optional, you should use is it if you want to allow an other website to show you images. You can add as many websites as you want by adding the same line.

http://www.yourdomain/pic.jpg : The url to a replacement image.


- Advertisement -Traffic Analysts Tool

3- A wordpress plugin :

The plugin called : Distilled Hotlink Builder and you can download it from the wordpress extend page.

This plugin uses a hidden message in a div layer and display it when the users right clicks the image.

- Advertisement -
Latest news
- Advertisement -

Liquid Web Storm VPS
Related articles
- Advertisement - Traffic Analysts Tool