Viewing file: img2.php (2.11 KB) -rwxr-xr-x Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
// Header("Content-type: image/gif");
Header("Content-type: image/jpeg"); //if your php support JPEG
$img_width=350;
$img_height=200;
$margin_left=25;
$margin_right=10;
$margin_top=20;
$margin_bot=10;
$bar_width=9;
$bar_space=4;
$title_font=5;
$im = imagecreate($img_width,$img_height);
$fond_img = imageColorAllocate($im, 204, 204, 204);
$noir=imageColorAllocate($im, 0, 0, 0);
$fond=imageColorAllocate($im,255,255,204);
$couleur_barre=imageColorAllocate($im,204,204,255);
ImageString($im,$title_font,($img_width-ImageFontWidth($title_font)*strlen($title))/2,0,$title,$noir);
#Draw rectangle which contain bars
imagefilledrectangle($im,$margin_left,$margin_top,$img_width-$margin_right,$img_height-$margin_bot,$fond);
# Manage data
$valeurs = explode(";",$sval);
//$img_width_barre=(int)(($img_width-22)/(1.5*sizeof($valeurs)+0.5));
$img_width_barre=$bar_width;
# Max function does not work correctly in php < 4
for ($i=0;$i<sizeof($valeurs);$i++) if ($valeurs[$i]>$max) { $max = $valeurs[$i]; }
#Draw bars
for ($i=0;$i<sizeof($valeurs);$i++) {
$x[i]=$margin_left+$i*($bar_space+$bar_width);
$img_height_barre=(int)(($valeurs[$i]*($img_height-40))/$max);
$img_height_barre=(int)(($valeurs[$i]*($img_height-$margin_top-$margin_bot-2*$bar_space))/$max);
imagefilledrectangle($im,$x[i],$img_height-$margin_bot-$bar_space-$img_height_barre,
$x[i]+$img_width_barre,$img_height-$margin_bot-$bar_space,
$couleur_barre);
if ($valeurs[$i] == $max) {
ImageString($im,2,4,($img_height-15-$img_height_barre)-(ImageFontHeight(2)/2),$valeurs[$i],$noir);
imageline($im,20,$img_height-15-$img_height_barre,$img_width-2,$img_height-15-$img_height_barre,$fond_img);
}
# write x axis every 2 hours
if (($i % 2)==0) ImageString($im,1,$x[i],$img_height-9,$i,$noir);
}
ImageString($im,2,0,0,"hits",$noir);
ImageString($im,1,($img_width-ImageFontWidth(1)*strlen("H")),$img_height-9,"heures",$noir);
// ImageGIF($im);
ImageJPEG($im);
ImageDestroy($im);
?>
|