PHP creates an image to display an email address?
Using PHP: How can I create an image to display an email address (to reduce spam)?
Meaning if I want to display " joe@example.com " on my web page since crawlers can easily find this text - I want to display the email address as an image that says " joe@example.com ".
How can I do it? I want the font to be:
- color: # 20c
- font: 11px normal tahoma
+2
a source to share
4 answers
A simple search that you could easily do.
However: (color, font and line are not the ones you specified)
header("Content-type: image/png");
$im = @imagecreate(110, 20)
or die("Cannot Initialize new GD image stream");
$background_color = imagecolorallocate($im, 0, 0, 0);
$text_color = imagecolorallocate($im, 233, 14, 91);
imagestring($im, 1, 5, 5, "A Simple Text String", $text_color);
imagepng($im);
imagedestroy($im);
Relevant function definitions:
+4
a source to share
Use them:
- header to tell the browser to expect images instead of HTML (PHP default). The image function docs have more information on this.
- imagettfbbox to find the required size for the image
- imagecreatetruecolor to create an image resource
- imagecolorallocate to highlight the color for the text
- imagettftext to draw text (read the example, that's pretty much all you need)
- imagepng to display the image in the browser
+3
a source to share