DEMO: See demo DOWNLOAD: str2img-1.0.tar.gz str2img-1.0.zip NAME: str2img: a library/plugin for displaying a string as an image. Great for displaying email addresses, captchas, etc. AUTHOR: Monte Ohrt (monte [AT] ohrt [DOT] com) VERSION: 1.0 DATE: Sept 5, 2008 WEBSITE: http://www.phpinsider.com/php/code/str2img/ DOWNLOAD: http://www.phpinsider.com/php/code/str2img/str2img.tar.gz http://www.phpinsider.com/php/code/str2img/str2img.zip SYNOPSIS: index.php --------- require('./libs/str2img.lib.php'); $str2img = new str2img(); echo $str2img->imgsrc('john@doe.com'); OUTPUT: see live demo: http://www.phpinsider.com/php/code/str2img/example.php DESCRIPTION: What is str2img? str2img is simply a way to display text as an image on a web page. This works good for hiding emails from spambots. str2img is utf-8 compliant, so any character set should render fine so long as your font supports your language. The GNU unifont works well with most of them. Although the text is encoded in the URL, it is not encrypted. Therefore, it is not impossible for someone to get the text from the encoded data, but this makes the task more complex for a spambot to gather it. FEATURES: Encoding keeps clear text out of the URLs. Install your own truetype fonts. Control font, font size, font angle, bgcolor and text color Comes with Smarty template plugin (optional) REQUIREMENTS: PHP must have the GD graphics library installed. INSTALLATION: Please NOTE: The installation process is crucial to get this library working correctly. Mistakes are not always easy to fix, as PHP errors can easily be hidden by image output errors. Follow them carefully! First, untar/unzip the contents of the distribution in your document root under a directory named "str2img". You should at the very least, install the following files: htdocs/ str2img/ fonts/ libs/ str2img.lib.php mkimage.php Second, install your truetype fonts! You will need at least one. The free GNU unifont is a wonderful font, covering nearly every language character set. See examples on the Demo page for directions on installing them. http://unifoundry.com/unifont.html EXAMPLE: Here is a full working example of how to use str2img. index.php --------- <?php // set this to appropriate system filepath require('./libs/str2img.lib.php'); $str2img = new str2img(); $str2img->font('unifont.ttf'); $str2img->fontsize(10); // in pixels $str2img->fontangle(0); // rotate in degrees $str2img->textcolor('000000'); // in hex $str2img->bgcolor('ffffff'); // in hex echo $str2img->imgsrc('john@doe.com'); PUBLIC PROPERTIES: $str2img->font -------------- examples: $str2img->font = 'unicode.ttf'; $str2img->font = 'arial.ttf'; This is used to set the truetype font to use. $str2img->fontsize ------------------ examples: $str2img->fontsize = 10; $str2img->fontsize = 20; This is used to set the font size in pixels. $str2img->fontangle ------------------- examples: $str2img->fontangle = 0; // default $str2img->fontangle = 45; This is used to rotate the text in degrees. $str2img->textcolor ------------------- examples: $str2img->textcolor = '000000'; $str2img->textcolor = 'eeffee'; This is used to set the color of the text in hexidecimal. $str2img->bgcolor ----------------- examples: $str2img->bgcolor = 'ffffff'; $str2img->bgcolor = 'ddffdd'; This is used to set the color of the background in hexidecimal. $str2img->id ------------ examples: $str2img->id = 'str2img'; $str2img->id = 'image'; This is used to set the id of the <img src id="..."> tag PUBLIC METHODS: function imgsrc($text) ---------------------- examples: echo $str2img->imgsrc('john@doe.com'); imgsrc() creates the <img src ...> tag necessary to render the image. function render($text) ---------------------- examples: $str2img->render($encoded_text); render() creates the actual output of the image. The text passed in must be in encoded form, usually from the output of $str2img->imgsrc(). SMARTY PLUGIN: To use the Smarty plugin, copy the Smarty plugin file function.str2img.php into your Smarty plugins folder. examples: {str2img text="john@doe.com"} {str2img text="john@doe.com" font="arial.ttf"} {str2img text="john@doe.com" fontsize="10"} {str2img text="john@doe.com" fontangle="45"} {str2img text="john@doe.com" textcolor="eeffee"} {str2img text="john@doe.com" bgcolor="000000"} This will output an <img src ...> tag to display the image. COPYRIGHT: Copyright(c) Monte Ohrt, Inc. All rights reserved. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. OTHER PROJECTS: View Monte's other projects