Miscellaneous
  Home arrow Miscellaneous arrow Page 5 - An Intro to Using the GD Image Library...
Codewalker Forums 
  Tutorials  
Database Articles  
Miscellaneous  
Navigation Usability  
PEAR Articles  
Programming Basics  
Server Administration  
XML Tutorials  
  Reviews  
Database Book Reviews  
Linux Book Reviews  
Miscellaneous Reviews  
PHP Book Reviews  
PHP Software Reviews  
Server Admin Reviews  
SQL Tool Reviews  
  Code Gallery  
Content Management Code  
Contest Code  
Counters Code  
Database Code  
Date Time Code  
Discussion Board Code  
Email Code  
File Manipulation Code  
GUI Code  
Link Farm Code  
Miscellaneous Code  
Search Code  
Site Navigation Code  
User Management Code  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
Download TestComplete 
Forums Sitemap 
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? 
MISCELLANEOUS

An Intro to Using the GD Image Library with PHP
By: Matt Wade
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    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

  • 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


    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


       · I've created a function that resizes an image and displays it in the browser or at...
       · Have you tried sending headers from the script anyway? If it's a separate script...
     

    MISCELLANEOUS ARTICLES

    - Using PHP to Stream MP3 Files and Prevent Il...
    - 10 Must Have Firefox Improvements
    - All About OpenOffice 3.0
    - Shell Script Writing
    - Loops in the UNIX Shell
    - The Test in the UNIX Shell
    - Data Streams and the UNIX Shell
    - Control Mechanisms of the UNIX Shell
    - Variables Within the UNIX Shell
    - The Shell and UNIX
    - In Detail: UNIX File Systems
    - Rights Management in UNIX
    - UNIX File Systems
    - The Terminal in UNIX
    - Operating Systems and UNIX





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