1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

Making Images With PHP

Discussion in 'PHP' started by digitalpoint, Mar 22, 2004.

  1. #1
    One of the really neat things about PHP (one of the many) is the ability to dynamically generate images by using the GD lib (although it's compiled in by default, so you don't need to know anything about it).
    SEMrush
    A simple example would be to display Yahoo WebRank graphic. The wr= part of the URL lets you get an image that ranges from 0-10 and display the bar graph.

    So how is this done?

    I made it easy on myself and made 3 different images that PHP pieces together. The background image, the bar part of the graph, and the top of the bar graph.


    The graphic.php file:
    <?php
    	$im = ImageCreateFromPNG ("bg.png");
    	$bar = ImageCreateFromPNG ("bar.png");
    	$bartop = ImageCreateFromPNG ("bartop.png");
    
    	for ($i = 1; $i <= $wr; $i++) {
    		ImageCopy ($im, $bar, 4, 62 - (6 * $i), 0, 0, 40, 6);
    	}
    
    	if ($wr > 0) ImageCopy ($im, $bartop, 4, 62 - (6 * $wr), 0, 0, 40, 4);
    
    	$col_mgrey = ImageColorAllocate ($im, 100, 100, 100);
    	$col_lgrey = ImageColorAllocate ($im, 200, 200, 200);
    
    	ImageString($im, 5, 20, 4, $wr, $col_mgrey);
    	ImageString($im, 5, 21, 5, $wr, $col_lgrey);
    
    	Header ("Content-type: image/png"); 
    	ImagePng ($im);
    	
    	ImageDestroy ($bar);
    	ImageDestroy ($bartop);
    	ImageDestroy ($im);
    ?>
    PHP:
    I won't get into complex image creation, but it can be done as well... an example is the attachment, which shows new users per day (from the keyword tracker) as of right now, with a unique line per language. Another interesting thing about the way that one is done is a SQL handle is fed to the function, so anything you can query with a SQL statement can be graphed.

    - Shawn
     

    Attached Files:

    digitalpoint, Mar 22, 2004 IP
    SEMrush
  2. Mr T

    Mr T Guest

    Messages:
    62
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Good work, more on PHP image abilities - last night I was amazed at how easy it was to create a thumbnail size copy of a user uploaded image, then you can show the small one (saving bandwidth) on a page as a link to the bigger one. Slightly off topic, just was incredibly pleased with my coding last night :)
     
    Mr T, Mar 22, 2004 IP
  3. rustybrick

    rustybrick User ID 3

    Messages:
    384
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    158
    #3
    Cool stuff.
     
    rustybrick, Mar 22, 2004 IP
  4. cosminx2003

    cosminx2003 Active Member

    Messages:
    581
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    60
    #4
    Really cool.
     
    cosminx2003, Apr 6, 2008 IP
  5. rajeev_seo

    rajeev_seo Peon

    Messages:
    211
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    its cool
    when you want any other method for ita check its link
    below
     
    rajeev_seo, Apr 24, 2011 IP
  6. ap2010

    ap2010 Guest

    Messages:
    41
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #6
    As far as simple bra graphs is concerned, you can do it with css sprites, no?
     
    ap2010, Apr 25, 2011 IP