Page 1 of 1

if statement in a gd image

Posted: Tue Dec 13, 2011 10:48 pm
by jay83r
is this possible... I'm trying to give an option and when selected it changed a number of lines to a different height

Code: Select all

  <label for="height"></label>
  <select name="height" id="height">
    <option value="2.4">2.4</option>
    <option value="2.7">2.7</option>
  </select>
</form>
<?php

require_once('./include/connection.php');
?>
<?php
header ("Content-type: image/png");
?>
<?php
$x1=$_GET['x1'];
$x2=$_GET['x2'];
$y1=$_GET['y1'];
$y2=$_GET['y2'];
$im = @ImageCreate (800, 600)
or die ("Cannot Initialize new GD image stream");
$background_color = ImageColorAllocate ($im, 255, 255, 255);
$line_color = ImageColorAllocate ($im, 0, 0, 0);

// imageline ($im,$x1,$y1,$x2,$y2,$text_color);
//front base line
if height = "2.4" 
imageline ($im,50,550,500,550,$line_color);
else//front left vertical
imageline ($im,50,550,50,200,$line_color);
endif//front right vertical
imageline ($im,500,550,500,200,$line_color);
//bottom of apex
imageline ($im,50,200,500,200,$line_color);
//left roof line
imageline ($im,50,200,275,100,$line_color);
//right roof line
imageline ($im,500,200,275,100,$line_color);
ImagePng ($im);
?> 

Re: if statement in a gd image

Posted: Wed Dec 14, 2011 2:58 am
by Dodon
Yes that's possible.

There are a few things you need to do:

- You need to either post the form to get the selected option or use javascript and use an AJAX call to generate the piece of php code that creates the image.
- second your if statement will not work this way, do something like below.

Code: Select all

if ($_POST['height'] == "2.4")
{ 
   imageline ($im,50,550,500,550,$line_color);
}
else//front left vertical
{
    imageline ($im,50,550,50,200,$line_color);
}
 
Above code is based on submitting the form, if you want to use an AJAX call easiest way is probably use a framework like JQuery or Prototype which makes making AJAX calls a bit easier.

Re: if statement in a gd image

Posted: Wed Dec 14, 2011 4:03 pm
by jay83r
Thanks for that, it's working well. One other thing i want to do is put the co-ordinates in a mysql db so i can call lines whenever i need them... how do i reference between mysql and where the co-ordinates need to go?