<?php


$g1= array(0,10,15,17,11,3,8,4,2,10,11,9,17);


function graphique ($data)
{
header ("Content-type: image/png");
$largeur=400;
$hauteur=300;

    // Création des instances d'image
//
$src = imagecreatefromjpeg('php.jpg');


$my_img = imagecreate( $largeur,$hauteur);
$background = imagecolorallocate( $my_img, 0, 0, 255 );
// Copie et fusionne
imagecopymerge($my_img, $src, 0, 0, 0, 0, $largeur,$hauteur,100);

$text_colour = imagecolorallocate( $my_img, 255, 255, 0 );
$line_colour = imagecolorallocate( $my_img, 128, 255, 0 );
$text_data = imagecolorallocate( $my_img, 250, 250, 250 );

$line_colour1 = imagecolorallocate( $my_img, 128, 255, 0 );
$line_colour2 = imagecolorallocate( $my_img, 128, 255, 0 );
$line_colour3 = imagecolorallocate( $my_img, 128, 255, 0 );
$line_colour4 = imagecolorallocate( $my_img, 128, 255, 0 );
$line_colour5 = imagecolorallocate( $my_img, 128, 255, 0 );
$line_colour6 = imagecolorallocate( $my_img, 128, 255, 0 );
$line_colour7 = imagecolorallocate( $my_img, 128, 255, 0 );
$line_colour8 = imagecolorallocate( $my_img, 128, 255, 0 );
$line_colour9 = imagecolorallocate( $my_img, 128, 255, 0 );
$line_colour10 = imagecolorallocate( $my_img, 128, 255, 0 );
$line_colour11 = imagecolorallocate( $my_img, 128, 255, 0 );
$line_colour12 = imagecolorallocate( $my_img, 128, 255, 0 );


imagestring( $my_img, 10, 50, 10, "Nombre de devis 2013", $text_colour );
imagesetthickness ( $my_img, 2 );
imageline( $my_img, 40, 28, 265, 28, $line_colour );


//calcul ratio
//$data=array();
$margebas=$hauteur-30;
$margehaut=$hauteur-250;
$margelaterale=20;
$pas=($largeur-(2*$margelaterale))/12;
$epais=15;

//$data= array(0,1,2,3,4,5,6,17,8,9,10,11,12);
// attention le array part de 0 et donc pour les mois commence à 0 et pas à 1

$max=max($data);
$coef=$margebas-$margehaut;
$echelle=($coef)/$max;
$Cx1=$margebas-($echelle*($data[1]));
$Cx2=$margebas-($echelle*($data[2]));
$Cx3=$margebas-($echelle*($data[3]));
$Cx4=$margebas-($echelle*($data[4]));
$Cx5=$margebas-($echelle*($data[5]));
$Cx6=$margebas-($echelle*($data[6]));
$Cx7=$margebas-($echelle*($data[7]));
$Cx8=$margebas-($echelle*($data[8]));
$Cx9=$margebas-($echelle*($data[9]));
$Cx10=$margebas-($echelle*($data[10]));
$Cx11=$margebas-($echelle*($data[11]));
$Cx12=$margebas-($echelle*($data[12]));


//imagestring( $my_img, 10, 50, 10, $margehaut." ".$Cx1." ".$Cx2." ".$Cx3." ".$Cx4, $text_colour );
//$Cx1=100;
//$Cx2=150;
//$Cx3=175;
//$Cx4=200;



imagefilledrectangle($my_img, $pas*1, $margebas, ($pas*1)+$epais, $Cx1, $line_colour);
imagefilledrectangle($my_img, $pas*2, $margebas, ($pas*2)+$epais, $Cx2, $text_colour);
imagefilledrectangle($my_img, $pas*3, $margebas, ($pas*3)+$epais, $Cx3, $line_colour);
imagefilledrectangle($my_img, $pas*4, $margebas, ($pas*4)+$epais, $Cx4, $text_colour);
imagefilledrectangle($my_img, $pas*5, $margebas, ($pas*5)+$epais, $Cx5, $line_colour);
imagefilledrectangle($my_img, $pas*6, $margebas, ($pas*6)+$epais, $Cx6, $text_colour);
imagefilledrectangle($my_img, $pas*7, $margebas, ($pas*7)+$epais, $Cx7, $line_colour);
imagefilledrectangle($my_img, $pas*8, $margebas, ($pas*8)+$epais, $Cx8, $text_colour);
imagefilledrectangle($my_img, $pas*9, $margebas, ($pas*9)+$epais, $Cx9, $line_colour);
imagefilledrectangle($my_img, $pas*10, $margebas, ($pas*10)+$epais, $Cx10, $text_colour);
imagefilledrectangle($my_img, $pas*11, $margebas, ($pas*11)+$epais, $Cx11, $line_colour);
imagefilledrectangle($my_img, $pas*12, $margebas, ($pas*12)+$epais, $Cx12, $text_colour);

imagestring( $my_img, 10, $pas*1,$margebas, "Jv", $text_colour );
imagestring( $my_img, 10, $pas*2,$margebas, "Fv", $text_colour );
imagestring( $my_img, 10, $pas*3,$margebas, "Ms", $text_colour );
imagestring( $my_img, 10, $pas*4,$margebas, "Av", $text_colour );
imagestring( $my_img, 10, $pas*5,$margebas, "Ma", $text_colour );
imagestring( $my_img, 10, $pas*6,$margebas, "Ju", $text_colour );
imagestring( $my_img, 10, $pas*7,$margebas, "Jl", $text_colour );
imagestring( $my_img, 10, $pas*8,$margebas, "Ao", $text_colour );
imagestring( $my_img, 10, $pas*9,$margebas, "Sp", $text_colour );
imagestring( $my_img, 10, $pas*10,$margebas, "Oc", $text_colour );
imagestring( $my_img, 10, $pas*11,$margebas, "Nv", $text_colour );
imagestring( $my_img, 10, $pas*12,$margebas, "Dc", $text_colour );

imagestring( $my_img, 10, $pas*1,$Cx1-15, $data[1], $text_data );
imagestring( $my_img, 10, $pas*2,$Cx2-15, $data[2], $text_data );
imagestring( $my_img, 10, $pas*3,$Cx3-15, $data[3], $text_data );
imagestring( $my_img, 10, $pas*4,$Cx4-15, $data[4], $text_data );
imagestring( $my_img, 10, $pas*5,$Cx5-15, $data[5], $text_data );
imagestring( $my_img, 10, $pas*6,$Cx6-15, $data[6], $text_data );
imagestring( $my_img, 10, $pas*7,$Cx7-15, $data[7], $text_data );
imagestring( $my_img, 10, $pas*8,$Cx8-15, $data[8], $text_data );
imagestring( $my_img, 10, $pas*9,$Cx9-15, $data[9], $text_data );
imagestring( $my_img, 10, $pas*10,$Cx10-15, $data[10], $text_data );
imagestring( $my_img, 10, $pas*11,$Cx11-15, $data[11], $text_data );
imagestring( $my_img, 10, $pas*12,$Cx12-15, $data[12], $text_data );

header( "Content-type: image/png" );
//header( "Content-type: text/html" );
imagepng( $my_img );
imagecolordeallocate( $line_color );
imagecolordeallocate( $text_color );
imagecolordeallocate( $background );
imagecolordeallocate( $src );
imagedestroy( $my_img );
}

//$g1= array(0,1,2,3,4,5,6,17,18,9,10,11,12);
graphique($g1);



?>


