Forum Moderators: coopster

Message Too Old, No Replies

PHP script to convert email addresses to graphic

Searched and searched - no luck

         

stormy

1:12 pm on Jan 19, 2006 (gmt 0)

10+ Year Member



Yesterday I spent a couple hours trying to find a PHP script to convert an email address into a graphic.

I'm looking for something where I can easly include a PHP file and pass the text which will be returned as a graphic.

I know this excludes people with screen readers and I know there are spambots supposedly able to OCR these, but for this particular application/customer is the best option.

Is anyone using something like this?

maccas

2:30 pm on Jan 19, 2006 (gmt 0)

10+ Year Member



From [uk2.php.net...]

<?php
header("Content-type: image/png");
$email = $_GET['email'];
$im = imagecreatefrompng("email.png");
$black = imagecolorallocate($im, 0, 0, 0);
$px = (imagesx($im) - 7.5 * strlen($email)) / 2;
imagestring($im, 3, $px, 9, $email, $black);
imagepng($im);
imagedestroy($im);
?>

Just create a blank 200 X 30 email.png it would be called from [yoursite...]

or if you want your own custom font change

imagestring($im, 3, $px, 9, $email, $black);

to

$font = 'verdref.ttf';
imagettftext($im, 10, 0, 20, 15, $black, $font, $email);

You will obviously need to upload verdref.ttf to your server.

Playaround with the numbers to align and change font size and 0, 0, 0 in $black for colour.

stormy

3:19 pm on Jan 19, 2006 (gmt 0)

10+ Year Member



The problem with that one is that the email address string will still be in the HTML.

I would need a way to pass that string through PHP so the email address is never revealed.

maccas

3:36 pm on Jan 19, 2006 (gmt 0)

10+ Year Member



How are you putting the email address on the page? Are they stored in a database?

maccas

3:53 pm on Jan 19, 2006 (gmt 0)

10+ Year Member



You could do something like this

<?php
header("Content-type: image/png");
$name= $_GET['name'];
$where= $_GET['where'];
$extension= $_GET['extension'];
$email = $name . "@" . $where . "." . $extension;
$im = imagecreatefrompng("email.png");
$black = imagecolorallocate($im, 0, 0, 0);
$px = (imagesx($im) - 7.5 * strlen($email)) / 2;
$font = 'verdref.ttf';
imagettftext($im, 10, 0, 20, 15, $black, $font, $email);

imagepng($im);
imagedestroy($im);
?>

print '<img src=/email.php?name=name&where=domainname&extension=com>';

stormy

3:53 pm on Jan 19, 2006 (gmt 0)

10+ Year Member



I'm just starting the project. I could store them in a database, but it would be overkill.

The ideal setup would be to call a simple include, pass the text via PHP and get the image returned. I guess actually creating those images only once would be good too.

If I was a programmer I guess I could do it, but I only know enough to more or less understand what a script is doing.

Thanks for the help!

stormy

4:06 pm on Jan 19, 2006 (gmt 0)

10+ Year Member



Beautiful! Excellent solution - thank you! :)

peco

1:34 am on Jan 20, 2006 (gmt 0)

10+ Year Member



What is the significance of the verdref.ttf?

I know it is a true type font, but why that one in particular?

maccas

9:16 am on Jan 20, 2006 (gmt 0)

10+ Year Member



No significance, it's just what I am using in a script I am working on.

peco

6:07 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



Oh right! LOL