PHP create image to display email address?

那年仲夏 提交于 2019-12-06 08:15:46

A simple search that you could easily do....

However: (color, font and string 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:

php.net/imagecreate

php.net/imagestring

Use these:

  • header, to tell the browser to expect an image instead of HTML (PHP's default). The image function doc pages have more information about this.
  • imagettfbbox, to find out the required size for the image
  • imagecreatetruecolor, to create the image resource
  • imagecolorallocate, to allocate a color for the text
  • imagettftext, to draw the text (read the example, it's almost all you need)
  • imagepng, to output the image to the browser

You should use gd image processing library.

If you are only doing this for one address you should not be doing this dynamically everytime the page loads for performance reasons. If this is the case you can find amny email obfuscator online such as this one:

http://digitalcolony.com/lab/maskemail/maskemail.aspx

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!