PHP GD random bar chart on image


 

PHP GD random bar chart on image

This example shows how to add random bar chart on image in php gd.

This example shows how to add random bar chart on image in php gd.

<?php

Header( "Content-type: image/jpeg");

$im = imagecreatefromjpeg( "images.jpg");

$red=ImageColorAllocate($im,255,0,0);

$green=ImageColorAllocate($im,0,255,0);

$blue=ImageColorAllocate($im,0,0,255);

$yellow=ImageColorAllocate($im,255,255,0);

$cyan=ImageColorAllocate($im,0,255,255);

$x=imagesx($im);

$y=imagesy($im);

srand(mktime());

$v=rand(); $v=$v/32768*200;

ImageFilledRectangle($im,10,200-$v,60,200,$red);

$v=rand(); $v=$v/32768*200;

ImageFilledRectangle($im,70,200-$v,120,200,$green);

$v=rand(); $v=$v/32768*200;

ImageFilledRectangle($im,130,200-$v,180,200,$blue);

$v=rand(); $v=$v/32768*200;

ImageFilledRectangle($im,190,200-$v,240,200,$yellow);

$v=rand(); $v=$v/32768*200;

ImageFilledRectangle($im,250,200-$v,300,200,$cyan);

Imagejpeg($im);

ImageDestroy($im);

?>

After running the program you will get the following output

Ads