Miscellaneous

  Home arrow Miscellaneous arrow Page 6 - An Intro to Using the GD Image Library...
MISCELLANEOUS

An Intro to Using the GD Image Library with PHP
By: Matt Wade
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 3 stars3 stars3 stars3 stars3 stars / 5
    2002-01-25

    Table of Contents:
  • An Intro to Using the GD Image Library with PHP
  • Getting to Know the Functions
  • More Functions
  • And Even More Functions
  • Putting It All Together
  • Let's Finish It Up

  •  
     

    SEARCH CODEWALKERS

    TOOLS YOU CAN USE

    advertisement

    An Intro to Using the GD Image Library with PHP - Let's Finish It Up


    (Page 6 of 6 )

    Ok, so we have it all together and have an image created. Now if you just try and stick that code in your page, it will not display correctly. The reason for this is that the browser doesn't know how to interpret the data that is coming at it. Some people solve this by writing the image to a temporary file; I don't like that method. If you write to a temporary file then you have to go back and clean those up. What a hassle. What I do is put all the code into its own PHP file and add a header to it. Then just act as if the PHP file was an image file and use standard HTML to include it.

    So, here is our finished clock all ready to go into its own PHP file :

    <?php
    Header
    ("Content-type: image/png");
    $time strftime("%I:%M:%S"time());
    $timearray explode(':',$time);
    $hour = (((int)$timearray[0]) * 60) + (int)$timearray[1];
    $minute = (int)$timearray[1];
    $second = (int)$timearray[2];
    if(
    $hour != 0) {
        
    $hourdegree = ((360 / (720 $hour)) - 90) % 360;
        if(
    $hourdegree &lt0) { $hourdegree 360 $hourdegree; }
    } else {
        
    $hourdegree 270;
    }
    if(
    $minute != 0) {
        
    $minutedegree = ((360 / (60 $minute)) - 90) % 360;
        if(
    $minutedegree &lt0) { $minutedegree 360 $minutedegree; }
    } else {
        
    $minutedegree 270;
    }
    if(
    $second != 0) {
        
    $seconddegree = ((360 / (60 $second)) - 90) % 360;
        if(
    $seconddegree &lt0) { $seconddegree 360 $seconddegree; }
    } else {
        
    $seconddegree 270;
    }

    $image imagecreate(100,100);
    $maroon ImageColorAllocate($image,123,9,60);
    $white ImageColorAllocate($image,255,255,255);
    $black ImageColorAllocate($image,0,0,0);

    ImageFilledRectangle($image,0,0,99,99,$white);
    ImageFilledEllipse($image,49,49,100,100,$black);
    ImageFilledEllipse($image,49,49,95,95,$maroon);
    ImageFilledEllipse($image,49,49,75,75,$white);
    ImageFilledEllipse($image,49,49,5,5,$maroon);
    ImageFilledArc($image,49,49,50,50,$hourdegree-4,$hourdegree+4,
    $maroon,IMG_ARC_PIE);
    ImageFilledArc($image,49,49,65,65,$minutedegree-3,$minutedegree+3,
    $maroon,IMG_ARC_PIE);
    ImageFilledArc($image,49,49,70,70,$seconddegree-2,$seconddegree+2,
    $black,IMG_ARC_PIE);

    ImageColorTransparent($image,$white);

    ImageTTFText ($image804411$white
    "/home/mjw21/www/images/arial.ttf","12");
    ImageTTFText ($image808953$white
    "/home/mjw21/www/images/arial.ttf","3");
    ImageTTFText ($image804796$white
    "/home/mjw21/www/images/arial.ttf","6");
    ImageTTFText ($image80553$white,
    "/home/mjw21/www/images/arial.ttf","9");

    imagePNG($image);
    imagedestroy($image);
    ?>

    Simple huh? There are lots of other functions available in the GD library, so get out there and experiment with them. If you look around my site you will see that the graphics for the code ratings are also created on the fly. The possibilities are endless!


    DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware.
    blog comments powered by Disqus

    MISCELLANEOUS ARTICLES

    - Oracle Database XE: Indexes and Sequences
    - Modifying Tables in Oracle Database XE
    - Oracle Database XE: Tables and Constraints
    - More on Oracle Databases and Datatypes
    - Oracle Database XE Datatypes: Datetime and L...
    - Oracle Database XE Datatypes: Character and ...
    - From Databases to Datatypes
    - Firefox 3.6.6 Released with Improved Plug-in...
    - Attention Bloggers: WordPress 3.0 Now Releas...
    - Reflection in PHP 5
    - Inheritance and Other Advanced OOP Features
    - Advanced OOP Features
    - Linux from Scratch V.6.6 Review
    - Linux Gaining in Strength
    - Install Slackware on Your Old PC


    © 2003-2012 by Developer Shed. All rights reserved. DS Cluster 8 - Follow our Sitemap