Jump to content

how to do an if statement in gd image


jay83r

Recommended Posts

does anyone know how to do an if statement in the middle of a gd image so that if a dropdown box is selected it draws different lines...

 

  <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 
imageline ($im,50,200,500,200,$line_color);
endif
//front left vertical
imageline ($im,50,550,50,200,$line_color);
//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);
?> 

Link to comment
https://forums.phpfreaks.com/topic/253135-how-to-do-an-if-statement-in-gd-image/
Share on other sites

This code

header ("Content-type: image/png");

MUST be the first output of this script!

 

If you like to make a selection, do it in a HTML page but not inside GD script. Then send this selection into you GD script using GET parameter(s). For example, you may do it with help of JavaScript.

Just for example: let pict.php is you GD script. Use JS, change id value to whatever you wish (set new SRC for tag IMG). Browser will request your script with a new parameter

<img src="pict.php?id=25" />

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.