Miscellaneous

  Home arrow Miscellaneous arrow Page 5 - 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 - Putting It All Together


    (Page 5 of 6 )

    Ok, now let's put all those functions together and create that clock! First we need to get a few variables set so that we have the proper time and all that. Here's a bit of code to do that, how we got this code is beyond the scope of this tutorial.

    <?php
    $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;
    }
    ?>

    Ok, there might be a more efficient way to get the degrees that we need, but this is the way I decided to do it. Anyway, on with making the image. Let's throw all those functions we saw earlier together and get an image created.

    <?php
    $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);
    ?>

    More Miscellaneous Articles
    More By Matt Wade

    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 4 - Follow our Sitemap