Say NO to image theft

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.

burglar

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;}

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
imagedestroy($img);

/* 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.

erreur

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.


You May Also Like

URL redirection the WHY and the HOW TO.

URL redirection or what we can call it  : – URL forwarding – Domain redirection – Domain forwarding are techniques on the WWW for making a web page available under many URLs. I- why using  URL redirection ? 1- Similar domain names : a) Users visiting a particular website may type the wrong spelling of […]

4 Tips On Making Money Through Blogging

COVID-19 has turned everything upside down for a lot of people. Where you may have been used to working in an office or at a store, you’re now probably stuck working from home. And if you aren’t now, you probably will be very soon. Another big issue that people are dealing with is, of course, […]

Tips for Writing Content for Blogs

Writing content for blogs is similar to writing content for ezines and newsletters, at the same time it is little different also. The similarity refers to the high quality of writing required and the differences usually refer to the style and presentation. Here is a look at some tips for writing content for blogs. 1. […]

6 Factors to Consider before Building affiliate marketing BLOG

A research shows that the Internet users have an attention span of just ten seconds. Well considering all factors this attention span is much smaller as compared to the other media forms. This makes it a very difficult task to keep a visitor interested in your affiliate marketing site. You have to attract and grab […]