WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
PHP Web Logs (BLogs)
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Submit Site
Forex Trading Online forex trading platform

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : Render TTF Text to PNG. Text message, font, size, rotation, padding, color, background, and transparency can all be defined via URL.
Categories : PHP, PHP Classes, Graphics Update Picture
Herman Veluwenkamp
Date : Jan 25th 2000
Grade : 4 of 5 (graded 11 times)
Viewed : 10925
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Herman Veluwenkamp
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

<?
/*
To draw the PNG - call this script with a URL like the following:

http://www.yoursite.com/text_png.php3?msg=testing+class&rot=15&size=48&font=fonts/ARIAL.TTF
*/

Header("Content-type: image/png");

class textPNG {
        var $font = 'fonts/TIMES.TTF'; //default font. directory relative to script directory.
        var $msg = "undefined"; // default text to display.
        var $size = 24;
        var $rot = 0; // rotation in degrees.
        var $pad = 0; // padding.
        var $transparent = 1; // transparency set to on.
        var $red = 0; // white text...
        var $grn = 0;
        var $blu = 0;
        var $bg_red = 255; // on black background.
        var $bg_grn = 255;
        var $bg_blu = 255;

function draw() {
        $width = 0;
        $height = 0;
        $offset_x = 0;
        $offset_y = 0;
        $bounds = array();
        $image = "";
        
        // determine font height.
        $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, "W");
        if ($this->rot < 0) {
                $font_height = abs($bounds[7]-$bounds[1]);                
        } else if ($this->rot > 0) {
                $font_height = abs($bounds[1]-$bounds[7]);
        } else {
                $font_height = abs($bounds[7]-$bounds[1]);
        }

        // determine bounding box.
        $bounds = ImageTTFBBox($this->size, $this->rot, $this->font, $this->msg);
        if ($this->rot < 0) {
                $width = abs($bounds[4]-$bounds[0]);
                $height = abs($bounds[3]-$bounds[7]);
                $offset_y = $font_height;
                $offset_x = 0;
                
        } else if ($this->rot > 0) {
                $width = abs($bounds[2]-$bounds[6]);
                $height = abs($bounds[1]-$bounds[5]);
                $offset_y = abs($bounds[7]-$bounds[5])+$font_height;
                $offset_x = abs($bounds[0]-$bounds[6]);
                
        } else {
                $width = abs($bounds[4]-$bounds[6]);
                $height = abs($bounds[7]-$bounds[1]);
                $offset_y = $font_height;;
                $offset_x = 0;
        }
        
        $image = imagecreate($width+($this->pad*2)+1,$height+($this->pad*2)+1);
        
        $background = ImageColorAllocate($image, $this->bg_red, $this->bg_grn, $this->bg_blu);
        $foreground = ImageColorAllocate($image, $this->red, $this->grn, $this->blu);
        
        if ($this->transparent) ImageColorTransparent($image, $background);
        ImageInterlace($image, false);
        
        // render it.
        ImageTTFText($image, $this->size, $this->rot, $offset_x+$this->pad, $offset_y+$this->pad, $foreground, $this->font, $this->msg);
        
        // output PNG object.
        imagePNG($image);
}
}

$text = new textPNG;

if (isset($msg)) $text->msg = $msg; // text to display
if (isset($font)) $text->font = $font; // font to use (include directory if needed).
if (isset($size)) $text->size = $size; // size in points
if (isset($rot)) $text->rot = $rot; // rotation
if (isset($pad)) $text->pad = $pad; // padding in pixels around text.
if (isset($red)) $text->red = $red; // text color
if (isset($grn)) $text->grn = $grn; // ..
if (isset($blu)) $text->blu = $blu; // ..
if (isset($bg_red)) $text->bg_red = $bg_red; // background color.
if (isset($bg_grn)) $text->bg_grn = $bg_grn; // ..
if (isset($bg_blu)) $text->bg_blu = $bg_blu; // ..
if (isset($tr)) $text->transparent = $tr; // transparency flag (boolean).

$text->draw();
?>



HTML_Graphs uses PHP to provide a consistent interface for creating HTML based charts. The user of the class sets up arrays that are passed to html_graph() which then takes care of all the messy HTML layout.
Categories : Graphics, Arrays, PHP, PHP Classes, Charts and Graphs
Three Cool Classes and One Trick
Categories : PHP, PHP Classes, Graphics, Email
Advanced Image WaterMarker
Categories : PHP, PHP Classes, GD image library, Graphics, Object Oriented
Simple class that uses GD to draw pie charts. After the class definition there's some sample code to demonstrate how you use the class.
Categories : Graphics, PHP, PHP Classes, GD image library, Charts and Graphs
HTML_Graphs provides a simple PHP interface for creating pure HTML charts.
Categories : Graphics, PHP, PHP Classes, Charts and Graphs
Image Cache
Categories : Graphics, PHP Classes, PHP
Class for processing image (resizing the image size to create thumb nails and small images from actual image without loosing the aspect ratio of the image)
Categories : PHP, PHP Classes, Graphics
imageMarker v 3.00 with new advanced features
Categories : PHP, PHP Classes, Graphics, GD image library
3dLib - a class for drawing in 3D space. Supported functions: Line, SetPixel, Polygon, FilledPolygon, etc. 3dChart() function has been added for one-call drawing of 3d charts. Support of mostly used 3d-transformations.
Categories : Graphics, Math., PHP Classes, PHP, Charts and Graphs
PHP interface class to the eBusiness Charts generatation remote service.
Categories : PHP, PHP Classes, Graphics, Charts and Graphs
Image Generation Class ( PNG Format )
Categories : PHP, GD image library, PHP Classes, Graphics
crop and resize image class using gd library function
Categories : PHP, PHP Classes, GD image library, Graphics
A class to draw real 3D graphics with surface area
Categories : Graphics, PHP, PHP Classes
file class , uploade file , download file already uploaded on another website
Categories : PHP, PHP Classes, Filesystem, Web Services
Authorize.net AIM Interface Class v1.0.0
Categories : PHP, PHP Classes, Ecommerce, Payment Gateways