Web Hosting Talk







View Full Version : Replace email with image.


raulgonzalez
12-19-2007, 09:50 AM
Hi,

I am looking for a function that can do the following:

take an email address from a string and based on the letters of the email it rewrites the email as an image.

Say example@example.com will display to the browser as example@example.com but as image instead of text.

The reason I want to do this is because I want to be able to display the email addresses to the public while still making it just a little difficult for someone to display the whole employees directory and just copy and paste and run a spam program.

I don't want to replace the email address with just an image that says "Email" because many people find it irritating to have their email program open when you click on those emails.

I had thought of using the explode() function and then replace each letter with its corresponding image, but not sure if there is something easier.

Please advice.

Xeentech
12-19-2007, 10:22 AM
There are a few libraries for each of the major languages that can do this, all you have to do is render some text. You can even make it fancy text so bots with OCR still can't read them.

What script/programming languages are you familiar with, there might be a standard lib built it.. The most popular such lib seems to be GD.

Steve_Arm
12-19-2007, 10:26 AM
From the manual:

<?php
$data = 'user@domain.com';
$im = imagecreatefromstring($data);
if ($im !== false) {
header('Content-Type: image/png');
imagepng($im);
}
else {
echo 'An error occurred.';
}
?>


And on click retrieve the e-mail from the database

raulgonzalez
12-19-2007, 10:56 AM
I use PHP. I like that idea of making them fancy. I will look into it.

raulgonzalez
12-19-2007, 01:41 PM
Ok I took your advice and it works great. I noticed that the quick time logo displays before the image is displayed. Does this mean that visitors without Quicktime Player will not be able to see it?

Below is one of many codes from php.net

<?php
// Set the content-type
header("Content-type: image/png");
// Create the image
$im = imagecreatetruecolor(400, 30);
// Create some colors
$white = imagecolorallocate($im, 255, 255, 255);
$grey = imagecolorallocate($im, 128, 128, 128);
$black = imagecolorallocate($im, 0, 0, 0);
imagefilledrectangle($im, 0, 0, 399, 29, $white);
// The text to draw
$text = 'Testing...';
// Replace path by your own font path
$font = 'arial.ttf';
// Add some shadow to the text
imagettftext($im, 20, 0, 11, 21, $grey, $font, $text);
// Add the text
imagettftext($im, 20, 0, 10, 20, $black, $font, $text);
// Using imagepng() results in clearer text compared with imagejpeg()
imagepng($im);
imagedestroy($im);
?>

Xeentech
12-19-2007, 01:46 PM
Quicktime shouldn't be displaying your PNGs.. are you using IE or something?

Post a link to an example and I'll tell you if it works on one of our testing "non-quicktime installed" machines..

raulgonzalez
12-19-2007, 01:59 PM
Sorry my bad. I was trying the example directly. There is another peace of HTML that I should be using instead of the code directly. It works fine now. I ended up using the following:


<?php
header("Content-type: image/png");
$string = $_GET['text'];
//$string = "Test String";
$im = imagecreatefrompng("images/email_button.png");
$orange = imagecolorallocate($im, 220, 210, 60);
$px = (imagesx($im) - 7.5 * strlen($string)) / 2;
imagestring($im, 3, $px, 9, $string, $orange);
imagepng($im);
imagedestroy($im);
?>

Then to call it.

<img src="email.php?text=email at email dot com">

Thanx for all your help

Xeentech
12-19-2007, 02:54 PM
<img src="email.php?text=email at email dot com">


The Email address will still be in the HTML as text though.. you need to obscure it some how.

raulgonzalez
12-19-2007, 04:30 PM
Well that was an exaple kind of. I pull the records out form MYSQL so a request to the search would have to be made for the HTML to display. Once displayed I understand that the HTML shows the email address.

Can the bot do multiple requests and gather the emails one by one or something similar?

Here is the site: http://www.laredo.edu/directory/search_form.php

Please advice

azizny
12-19-2007, 06:05 PM
Encode the string using this function:

http://www.phptricks.com/?L*6*Encoding%20and%20Decoding%20In%20PHP

It should be unbreakable after that.

Peace,

foobic
12-19-2007, 06:07 PM
It will be quite wasteful generating the images for every request, so a suggestion:

Cache the image files in their own directory under filenames based on the database id. eg. /directory/emails/42.png
In .htaccess, use mod_rewrite to detect when the cached image doesn't exist and call your PHP program to generate a new one.
When the PHP program generates an image it first saves it in the cache directory and then serves it to the client.
When you change a record in your database, delete the cached image.


page:
<img src="/directory/emails/42.png" alt="email address of John Smith" />

.htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /directory/emails/(.*) email.php?id=$1 [L]

email.php:
<?php
...
preg_match("/(\d+)\.php/", $_GET['id'], $matches);
$id = $matches[1];
// fetch e-mail address from db for user_id $id
...
// create GD image
...
// Save image to file
imagepng($im, "/path/to/directory/emails/$id.png");
// Serve image to visitor
header("Content-type: image/png");
imagepng($im);
// Clean up
...
?>