@ 2015-11-22T11:18:03Z <?php
<?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 = "ARIALBD.TTF";
$graphCanX = ( $totalwidth - $xgutter*2 );
$graphCanY = ( $totalheight - $ygutter*2 - $bottomspace );// starting draw position x - axis
$posX = $xgutter; // starting draw pos - y - axis
$posY = $totalheight - $ygutter - $bottomspace;
$cellwidth = (int) (( $graphCanX - ( $internalgap * ( $total-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--;
}
}
$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-$cellheight), ($posX+$cellwidth), $posY, $blue );
$box = ImageTTFbBox( $textsize, 0, $font, $key );
$tw = $box[2];
ImageTTFText( $image, $textsize, 0, ($center-($tw/2)),
($totalheight-$ygutter), $black, $font, $key );
$posX += ( $cellwidth + $internalgap);
}
imagegif( $image );
Enable javascript to submit You have javascript disabled. You will not be able to edit any code.
Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).
Version System time (s) User time (s) Memory (MiB) 5.6.15 0.013 0.077 18.18 5.6.14 0.013 0.043 18.14 5.6.13 0.003 0.090 18.14 5.6.12 0.000 0.047 20.98 5.6.11 0.007 0.050 21.13 5.6.10 0.010 0.073 20.97 5.6.9 0.007 0.050 20.95 5.6.8 0.000 0.043 20.28 5.5.30 0.013 0.077 17.93 5.5.29 0.003 0.053 17.98 5.5.28 0.000 0.060 20.64 5.5.27 0.003 0.040 20.88 5.5.26 0.000 0.063 20.86 5.5.25 0.030 0.047 20.65 5.5.24 0.023 0.073 20.36
preferences:dark mode live preview
138.07 ms | 1394 KiB | 7 Q