Page 1 of 1

need help with GD

Posted: Fri Jul 11, 2008 7:16 am
by Monopoly
So ... I have this on a page :


$width=$coef*130;
echo "<p align=\"left\"><img src=\"image.php\">&nbsp;&nbsp;".$choice."<small> (".$mycount.")</small></p>";


and image.php contains the following :


<?php
header("Content-type: image/gif");
$im = imagecreate(130, 3);
$black = imagecolorallocate($im, 0, 0, 0);
$red = imagecolorallocate($im, 255, 0, 0);
imagefilledrectangle($im,0, 0, $width, 3, $red);
imagegif($im);
?>


But the red part doesn't appear , and I think it has something to do with $width , the imagefilledrectangle() doesn't get the $width ...


Can you please help me ?

Re: need help with GD

Posted: Fri Jul 11, 2008 8:02 am
by onion2k
You're right about the issue. The image is a separate script entirely. It can't access any variables set in the page script. Either pass the width as a GET variable (eg call the image with image.php?width=$width ), or calculate the width value in the image script in the same way you calculate it in the page script, or put the width value in the session and retrieve it in the image script.

Re: need help with GD

Posted: Fri Jul 11, 2008 10:55 am
by Monopoly
indeed...$_GET['width']...

Thanks !! is there a way I can give a +1 or a up ? :drunk:

Re: need help with GD

Posted: Fri Jul 11, 2008 11:13 am
by onion2k
No, we don't do that here. Besides, everyone already knows I'm awesome.

:drunk: indeed!