PHP
  Home arrow PHP arrow Page 6 - Generating Images on the Fly With PHP
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PHP

Generating Images on the Fly With PHP
By: Divyesh Jariwala
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 58
    2001-12-13

    Table of Contents:
  • Generating Images on the Fly With PHP
  • The GD image library
  • Creating our image
  • Displaying our image
  • Generating the random number
  • Changing the font of our random number
  • Conclusion

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Generating Images on the Fly With PHP - Changing the font of our random number


    (Page 6 of 7 )

    To control the look and style attributes of our random number, we can replace the imagestring function with the imagettftext function, which lets us control some of the aspects of the font used to render the text.

    The imagettftext function takes eight arguments, as described below:

    array Imagettftext (int im, int size, int angle, int x, int y, int col, string fontfile, string text)
    1. im: A reference to an image canvas created using the imagecreate function
    2. size: The height of the font, in pixels
    3. angle: The rotation of the font. Use 0 for standard horizontal display
    4. x: The starting x co-ordinate of where the text will be drawn
    5. y: The starting y co-ordinate of where the text will be drawn
    6. col: A reference to a color created using the imagecolorallocate function
    7. fontfile: The path and filename to the font that the text will be rendered in (more on this in a minute)
    8. text: The actual string of text to be drawn
    So, for our example, we would used the imagettftext function instead of the imagestring function, like this:

    Imagettftext($img_number, 30,0,10,33,$black,'trebuchet.ttf',$number);

    Notice the seventh argument? It’s the location of the true-type font file that will be used to render our text onto the image. In our example, the file trebuchet.ttf is in the same directory as our script. Trebuchet.ttf is contained in the support material at the end of this article.

    The Imagettftext file uses the FreeType font support, which is built-in to all of the latest releases of the GD image library. You can read more about the FreeType project at http://www.freetype.org/freetype2/index.html.

    Once you have saved the random_number.php file with the new Imagettftext function instead of the imagestriing function, reload the page in your browser. You should see something like this:

    Our random number now has a larger, bolder font

    More PHP Articles
    More By Divyesh Jariwala


     

    PHP ARTICLES

    - Making Usage Statistics in PHP
    - Installing PHP under Windows: Further Config...
    - File Version Management in PHP
    - Statistical View of Data in a Clustered Bar ...
    - Creating a Multi-File Upload Script in PHP
    - Executing Microsoft SQL Server Stored Proced...
    - Code 10x More Efficiently Using Data Access ...
    - A Few Tips for Speeding Up PHP Code
    - The Modular Web Page
    - Quick E-Commerce with PHP and PayPal
    - Regression Testing With JMeter
    - Building an Iterator with PHP
    - PHP Frontend to ImageMagick
    - Using PEAR's mimeDecode Module
    - Incoming Mail and PHP







    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
    Stay green...Green IT