By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,044 Members | 1,291 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,044 IT Pros & Developers. It's quick & easy.

Image_Graph Problem

P: n/a
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.

Jul 17 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
On Mon, 17 Jul 2006 19:34:59 GMT, Shawn Hamzee <ha****@sbcglobal.net.INVALID>
wrote:
>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.
Have you output an appropriate Content-type header for the image format you're
using?

--
Andy Hassall :: an**@andyh.co.uk :: http://www.andyh.co.uk
http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool
Jul 17 '06 #2

P: n/a

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.

Thanks.

On 7/17/06 15:51, in article di********************************@4ax.com,
"Andy Hassall" <an**@andyh.co.ukwrote:
On Mon, 17 Jul 2006 19:34:59 GMT, Shawn Hamzee <ha****@sbcglobal.net.INVALID>
wrote:
>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.

Have you output an appropriate Content-type header for the image format
you're
using?
Jul 17 '06 #3

P: n/a
Rik
Shawn Hamzee wrote:

Don't toppost
<an**@andyh.co.ukwrote:
><ha****@sbcglobal.net.INVALIDwrote:
>>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.

Have you output an appropriate Content-type header for the image
format you're
using?
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.
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
dynamic.

Grtz,
--
Rik Wasmus
Jul 17 '06 #4

P: n/a
Shawn Hamzee wrote:
>
Don't toppost
><an**@andyh.co.ukwrote:
>><ha****@sbcglobal.net.INVALIDwrote:
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.

Have you output an appropriate Content-type header for the image
format you're
using?
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.

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
dynamic.

Grtz,
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!

Thanks

Jul 17 '06 #5

P: n/a
Rik
Shawn Hamzee wrote:
>Shawn Hamzee wrote:

Don't toppost
>><an**@andyh.co.ukwrote:
<ha****@sbcglobal.net.INVALIDwrote:
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.

Have you output an appropriate Content-type header for the image
format you're
using?
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.

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 dynamic.

Grtz,

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!

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

$new = imagecreatetruecolor($x, $y + $width - 1);
$back = imagecolorallocate($new,$red,$green,$blue);
imagefill($new,0,0,$back);
imagecopyresampled($new,$image,0,0,0,0,$x,$y,$x,$y );
for($i=1;$i<=$width;$i++){
imagecopyresampled($new,$image,0,$y+$i-1,0,$y-$i,$x,1,$x,1);
}
imagealphablending($new,true);
for($i=0;$i < $width;$i++){
//$trans = floor(0.03125 * $i * $i);
$trans = $i *2;
$color = imagecolorallocatealpha($new,$red,$green,$blue,$tr ans);
imageline($new,0,$y+$width-$i,$x,$y+$width-$i,$color);
}
header("Content-type: image/png");
imagepng($new);
imagedestroy($image);
imagedestroy($new);
}

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

transborder('http://nl3.php.net/images/php.gif',50,255,240,240);
?>
The magic happens here:
header("Content-type: image/png");
imagepng($new);

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);
}
register_shutdown_function("shutdown_func");

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 :-)

Grtz,
--
Rik Wasmus
Jul 17 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.