need help with GD

Not for 'how-to' coding questions but PHP theory instead, this forum is here for those of us who wish to learn about design aspects of programming with PHP.

Moderator: General Moderators

Post Reply
Monopoly
Forum Commoner
Posts: 41
Joined: Wed May 21, 2008 1:19 pm

need help with GD

Post 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 ?
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: need help with GD

Post 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.
Monopoly
Forum Commoner
Posts: 41
Joined: Wed May 21, 2008 1:19 pm

Re: need help with GD

Post by Monopoly »

indeed...$_GET['width']...

Thanks !! is there a way I can give a +1 or a up ? :drunk:
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: need help with GD

Post by onion2k »

No, we don't do that here. Besides, everyone already knows I'm awesome.

:drunk: indeed!
Post Reply