Image_Graph Problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello All,

I am having a problem with Image_Graph on php 5.1.4. I installed the package
and all of its dependencies through pear installer without any hitches. Then
I started to add some very simple code to create a graph in an existing php
page. I added the code for the graph and added the elements of it plus some
static data. However, when I browse the page, I get garbled data instead of
the graph. Has anyone ever run into this problem. I am testing this on an xp
test bed for now.

I am thinking the fact that I'm getting garbled data means that the class
creation has gone well; however rendering the graph is not happening for
some reason.

Re: Image_Graph Problem


Quoted text here. Click to load it

 Have you output an appropriate Content-type header for the image format you're

Andy Hassall :: :: :: disk and FTP usage analysis tool

Re: Image_Graph Problem

Actually, I just found out what is going on:
In order to use image_graph, one cannot have both a graph and html (php
generated or otherwise) on the same page.

So in order to get around this, you'll have to save the graph to an image
file (.png) and then echo a link in the script for it.


On 7/17/06 15:51, in article,

Quoted text here. Click to load it

Re: Image_Graph Problem

Shawn Hamzee wrote:

Don't toppost

Quoted text here. Click to load it

Not really.
You could save the portion of your script that makes the graph something
like graphcreator.php, and echo that as the source for your image. That way
it will always stay up to date without any constant diskwriting. Depending
on how much people will see the graph storing it and refreshing it
periodically could save some overhead. If it's just some statistics a few
people will check out a couple of times per week I'd keep it totally

Rik Wasmus

Re: Image_Graph Problem

Quoted text here. Click to load it

Really! Do you have a working example of your method? I'd be interested to
see how the source of image can be a php file!


Re: Image_Graph Problem

Shawn Hamzee wrote:
Quoted text here. Click to load it

Not from the graph, but kind of a mirror effect with fade i recently worked
(NOTE: by no means a finished product, it has some bugs in it!){
function transborder($image,$width,$red,$green,$blue){
 $size = @getimagesize($image);
 if($size===false) return false;
  case 1:
   $image = imagecreatefromgif($image);
  case 2:
   $image = imagecreatefromjpeg($image);
  case 3;
   $image = imagecreatefrompng($image);
   return false;
 $x = $size[0];
 $y = $size[1];

 $new = imagecreatetruecolor($x, $y + $width - 1);
 $back = imagecolorallocate($new,$red,$green,$blue);
 for($i=0;$i < $width;$i++){
  //$trans = floor(0.03125 * $i * $i);
  $trans = $i *2;
  $color = imagecolorallocatealpha($new,$red,$green,$blue,$trans);
 header("Content-type: image/png");

/* now we can call the function with the following arguments:
    string     imagelocation (local or url)
    int        width mirrored surface
    int red
    int green
    int blue*/


The magic happens here:
 header("Content-type: image/png");

Send the right header, and imagepng() (or imagejpeg() or imagegif()) will
output it directly. And never, ever, forget to imagedestroy() you images...
A good tip was to register a shutdown function:

function shutdown_func() {
   global $image,$new;
   if($img) imagedestroy($img);
   if($new) imagedestroy($new);

Allthough this does take an existing image, it creates a totally new one.
Creating an image with imagefilledpolygon(), imageline() and the like is
also possible. with those kind of functions the graph is actually made.

Check out the extensive GD library, a lot is possible (and even more
impossible unfortunately :-)

Rik Wasmus

Site Timeline