bbdog (2) [Avatar] Offline
#1
Hi I am running GD on Perl 5.8.7 build 815 and am trying to embed a GD generated piechart in HTML. If I display it without any HTML it performs this fine.

This is the code:

#!/usr/bin/perl -w
use CGI;
use GD::Graph::pie;
require "cgi-lib.pl";
use DBI;


use CGI qw/:standard/;

my $cgi = CGI->new();
print $cgi->header( -type => "image/gif" );

my $win = 1;
my $draw = 5;
my $lost = 5;

my $maxi = 0;
my $maxi = $lost*3;
my $maxi = $maxi+($win*3);
my $maxi = $maxi+$draw;


my $a = ((1*3)/$maxi)*100;
my $aa = sprintf("%.2f", $a);
my $b = (5/$maxi)*100;
my $bb = sprintf("%.2f", $b);
my $c = ((5*3)/$maxi)*100;
my $cc = sprintf("%.2f", $c);

my @data = ( ["win $aa%","draw $bb%","lost $cc%"], [ $aa, $bb,

$cc] );

my $graph = new GD::Graph::pie( 350, 350 );

$graph->set( title => "where your points have gone",
dclrs => [ qw( #D6D6FF #CECECE #FFFFFF ) ],
pie_height => 0,
start_angle => 90 );

print $graph->plot(@data)->gif();



If I add the following:

print "Content-type: text/html

";
print '<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">';
print "<HTML><BODY>";
print '<link href="../style.css" rel="stylesheet" type="text/css">';
print "<center>";
print '<link rel="stylesheet" href="../../common/en-us.css" type="text/css" media="screen" />';

it renders the display as such (I am only displaying the first few lines)

Content-type: text/html
GIF89a^^ÂÿÿÿÖÖÿÎÎÎÿÿÿ!ù,^^þºÜþ0ÊI«½8ëÍ»ÿ`(Ždižhª®lë¾p,ÏtmÓÁ­+¹Õo¿pH„‹°£Dya"ŸÐ˜3j X­@u+;örWÆõÆ.Ɠ


Any help would be appreciated, thanks
bbdog (2) [Avatar] Offline
#2
Re: Embedding GD graphics in HTML displays incorrect format
Ok I found out what I was doing wrong. I should be writing the image to a file and reading the image back, this makes sense now. I can print images and embed them in a HTML.