All pastes #421712 Raw Edit

Anonymous

public text v1 · immutable
·published 2007-04-03 00:15 UTC
rendered paste body
 <?php
 header("Content-type: image/gif");
 $cells = array ( liked=>200, hated=>400, indifferent=>900 );
 $max = max( $cells );
 $total = count ( $cells );
 $totalwidth = 300;
 $totalheight = 200;
 $xgutter = 20; // left/right margin
 $ygutter = 20; // top/bottom margin
 $internalgap = 10; // space between cells
 $bottomspace = 30; // gap at the bottom (in addition to margin)
 $font = "/usr/local/jdk121_pre-v1/jre/lib/fonts/LucidaSansRegular.ttf";
 $graphCanX = ( $totalwidth &#8722; $xgutter*2 );
 $graphCanY = ( $totalheight &#8722; $ygutter*2 &#8722; $bottomspace );// starting draw position x - axis
 $posX = $xgutter; // starting draw pos - y - axis
 $posY = $totalheight &#8722; $ygutter &#8722; $bottomspace;
 $cellwidth = (int) (( $graphCanX &#8722; ( $internalgap * ( $total&#8722; 1 ) )) / $total) ;
 $textsize = (int)($bottomspace);
 // adjust font size
 while ( list( $key, $val ) = each ( $cells ) )
 {
 while ( 1 )
 {
 $box = ImageTTFbBox( $textsize, 0, $font, $key );
 $textWidth = abs( $box[2] );
 if ( $textWidth < $cellwidth )
 break;
 $textsize&#8722; &#8722; ;
 }
 }
 $image = imagecreate( $totalwidth, $totalheight );
 $red = ImageColorAllocate($image, 255, 0, 0);
 $blue = ImageColorAllocate($image, 0, 0, 255 );
 $black = ImageColorAllocate($image, 0, 0, 0 );
 $grey = ImageColorAllocate($image, 100, 100, 100 );
 reset ($cells);
 while ( list( $key, $val ) = each ( $cells ) )
 {
 $cellheight = (int) (($val/$max) * $graphCanY);
 $center = (int)($posX+($cellwidth/2));
 imagefilledrectangle( $image, $posX, ($posY&#8722; $cellheight), ($posX+$cell width), $posY, $blue );
 $box = ImageTTFbBox( $textsize, 0, $font, $key );
 $tw = $box[2];
 ImageTTFText( $image, $textsize, 0, ($center&#8722; ($tw/2)),
 ($totalheight&#8722; $ygutter), $black, $font, $key );
 $posX += ( $cellwidth + $internalgap);
 }
 imagegif( $image );
 ?>