[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2498
  • Last Modified:

PHP5 GD (JpGraph) Garbled Text (binary output in web browser)

I'm trying to get JpGraph up and running with the GD library and PHP but when I use the below script from the JpGraph documentation "Verifying that you have the GD library installed" -- all I get is garbled text where the image should be like this, "‰PNG  IHDR,ÈݽK¢IDATxœíÜ1....".  I don't get any errors, just garbled text.  How do I get an image instead of binary output on my browser window?

<?php
 $im = @ ImageCreate ( 150, 100)
    or die ( "Cannot create a new GD image.");
$background_color  = ImageColorAllocate  ($im, 255,  255, 255);
$text_color  = ImageColorAllocate  ($im, 233,  14, 91);
ImageString  ($im, 1,  5, 5,  "A Simple Text String", $text_color );
header ("Content-type: image/png");
ImagePng ($im);
?>

gd_info()
GD Support  enabled  
GD Version  bundled (2.0.28 compatible)  
FreeType Support  enabled  
FreeType Linkage  with freetype  
FreeType Version  2.1.9  
GIF Read Support  enabled  
GIF Create Support  enabled  
JPG Support  enabled  
PNG Support  enabled  
WBMP Support  enabled  
XBM Support  enabled  
Server API  Apache 2.0 Handler  
System  Windows NT 5.0 build 2195  
Registered PHP Streams  php, file, http, ftp, compress.zlib  
PHP Version 5.0.4RC2-dev
http://www.t1shopper.com/
0
Geoff Millikan
Asked:
Geoff Millikan
  • 4
  • 2
1 Solution
 
Geoff MillikanAuthor Commented:
I updated to "PHP Version 5.2.0-dev" and Apache 2.2.2 to see if that would fix anything and it didn't make it better.  phpinfo says:
Configure Command  cscript /nologo configure.js "--enable-snapshot-build" "--with-gd=shared"
_SERVER["SERVER_SOFTWARE"] Apache/2.2.2 (Win32) DAV/2 PHP/5.2.0-dev

Help!
0
 
Geoff MillikanAuthor Commented:
I've tried everything and now I'm back to Apache/2.0.52 (Win32) PHP/5.2.0-dev and the image is still coming out as gibberish binary data instead of an image.  I give up.  Help!
0
 
Richard QuadlingSenior Software DeverloperCommented:
I suspect that there is SOMETHING happening to change the header you are sending.

Now, according to the manual, you do NOT need to use the header().

<?php
$im = imagecreatefrompng("test.png");
imagepng($im);
?>


But there is a user note : vladson at pc-labs dot info (04-Jul-2005 04:00)

To send 'Content-Length' header (like in static pictures case) i use "Output handler" like this...
<?php
// Output handler
function output_handler($img) {
header('Content-type: image/png');
header('Content-Length: ' . strlen($img));
return $img;
}
// Image output
ob_start("output_handler");
imagepng($im);
ob_end_flush();
?>


So ...

1 - Try removing the header('Content-type: image/png'); line
2 - Try using the output_handler example code above.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
Geoff MillikanAuthor Commented:
Running the above smaple script #1 provided by RQuadling produced:
Warning: imagecreatefrompng(test.png) [function.imagecreatefrompng.html]: failed to open stream: No such file or directory in C:\Web\dev\gd.php on line 11
Warning: imagepng(): supplied argument is not a valid Image resource in C:\Web\dev\gd.php on line 12

Running the above sample script #2 provided by RQuadling produced:
Warning: imagepng(): supplied argument is not a valid Image resource in C:\Web\dev\gd.php on line 24

Help!
0
 
Geoff MillikanAuthor Commented:
Although this problem was not resolved, thanks so much for your help - I'm going to award you points anyway for the effort.  This charting software was too hard to figure out so we went with another solution http://www.infosoftglobal.com/FusionCharts/
0
 
Richard QuadlingSenior Software DeverloperCommented:
Ah!

Come on, did you not actually READ the code?

imagecreatefrompng(...)

means there has to be an existing PNG file.

The issue is your additional header statement.

Did you try just removing it?
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now