Please disregard the above post. I have managed to get php to draw the image I want however I have run into another problem.
When I subtract the finishtime from the starttime, it will only return a whole number and never a decimal. Is there anything I can do about this? example values would be 08:00:00 and 16:30:00. For which the result should be 8.5 and not 8 which my script is returning.
Here is my code so far:
[php]<?php
############################# draw grid
header(“Content-type: image/jpeg”);
$height = 21;
$width = 497;
$im = imagecreate($width,$height);
$white = imagecolorallocate($im,255,255,255);
$black = imagecolorallocate($im,0,0,0);
$red = imagecolorallocate($im,255,0,0);
//draw grid
imagerectangle($im, 8, 1, 28, 20, $black);
imagerectangle($im, 28, 1, 48, 20, $black);
imagerectangle($im, 48, 1, 68, 20, $black);
imagerectangle($im, 68, 1, 88, 20, $black);
imagerectangle($im, 88, 1, 108, 20, $black);
imagerectangle($im, 108, 1, 128, 20, $black);
imagerectangle($im, 128, 1, 148, 20, $black);
imagerectangle($im, 148, 1, 168, 20, $black);
imagerectangle($im, 168, 1, 188, 20, $black);
imagerectangle($im, 188, 1, 208, 20, $black);
imagerectangle($im, 208, 1, 228, 20, $black);
imagerectangle($im, 228, 1, 248, 20, $black);
imagerectangle($im, 248, 1, 268, 20, $black);
imagerectangle($im, 268, 1, 288, 20, $black);
imagerectangle($im, 288, 1, 308, 20, $black);
imagerectangle($im, 308, 1, 328, 20, $black);
imagerectangle($im, 328, 1, 348, 20, $black);
imagerectangle($im, 348, 1, 368, 20, $black);
imagerectangle($im, 368, 1, 388, 20, $black);
imagerectangle($im, 388, 1, 408, 20, $black);
imagerectangle($im, 408, 1, 428, 20, $black);
imagerectangle($im, 428, 1, 448, 20, $black);
imagerectangle($im, 448, 1, 468, 20, $black);
imagerectangle($im, 468, 1, 488, 20, $black);
//draw shift line
$starttime = $_GET['starttime'];
$finishtime = $_GET[‘finishtime’];
$stime = substr($starttime, 0, 5); // ignore these for now as they are the time
$etime = substr($finishtime, 0, 5); // strings i will put at the start and end of each line
//start and end points for lines based on times.
$shiftlength = $finishtime - $starttime; // this is the formula subtracting the start and finishtimes
$startpoint = $starttime * 20 + 8;
$endpoint = $startpoint +($shiftlength * 20);
imagestring($im, 2, 350, 5, $shiftlength, $black); // echos 8 not 8.5
imageline($im, $startpoint, 10, $endpoint, 10, $red);
imagejpeg($im);
#####################
?>[/php]
For those wanting to use this script call it via the following:
[php][/php]
Any help with my arithmetic issue would be greatly appreciated.
Kind Regards
Adam