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
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" />

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.