Using GD Library Functions

This is a discussion on Using GD Library Functions within the PHP Language forums, part of the PHP Programming Forums category; I would like use some of the GD image functions, so I ran a couple of short scripts to see ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-03-2004
Uncle_Alias
 
Posts: n/a
Default Using GD Library Functions

I would like use some of the GD image functions, so I ran a couple of
short scripts to see if it worked, such as:

<?php

/* Create a red square */
$image = imagecreate(200, 200);
$colorRed = imagecolorallocate($image, 255, 0, 0);
imagefill($image, 0, 0, $colorRed);

//send image
header("Content-type: image/jpeg");
imagejpeg($image);

?>

but all they generates are garbage characters and no image, starting
with:
ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default
quality ÿÛC ... (etc.)

I then ran a script to see what version was installed
(var_dump(gd_info());)and it generated: ["GD Version"]=> string(24)
"bundled (2.0 compatible)"


So why doesn't it generate a jpeg? Am I doing something incorrectly or
is it the library itself? (This is using a hosting account at
godaddy.com. It is not PHP or a GD library that I installed).

Thanks,
Eric
Reply With Quote
  #2 (permalink)  
Old 01-03-2004
CountScubula
 
Posts: n/a
Default Re: Using GD Library Functions

Can you post a link to a test? I can use my server check on my site to take
a look at whats going on.

--
Mike Bradley
http://gzen.myhq.info -- free online php tools
"Uncle_Alias" <zephinilium@yahoo.com> wrote in message
news:e1eff209.0401021505.12133746@posting.google.c om...
> I would like use some of the GD image functions, so I ran a couple of
> short scripts to see if it worked, such as:
>
> <?php
>
> /* Create a red square */
> $image = imagecreate(200, 200);
> $colorRed = imagecolorallocate($image, 255, 0, 0);
> imagefill($image, 0, 0, $colorRed);
>
> //send image
> header("Content-type: image/jpeg");
> imagejpeg($image);
>
> ?>
>
> but all they generates are garbage characters and no image, starting
> with:
> ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default
> quality ÿÛC ... (etc.)
>
> I then ran a script to see what version was installed
> (var_dump(gd_info());)and it generated: ["GD Version"]=> string(24)
> "bundled (2.0 compatible)"
>
>
> So why doesn't it generate a jpeg? Am I doing something incorrectly or
> is it the library itself? (This is using a hosting account at
> godaddy.com. It is not PHP or a GD library that I installed).
>
> Thanks,
> Eric



Reply With Quote
  #3 (permalink)  
Old 01-03-2004
SwissCheese
 
Posts: n/a
Default Re: Using GD Library Functions

"Uncle_Alias" <zephinilium@yahoo.com> wrote in message
news:e1eff209.0401021505.12133746@posting.google.c om...
> I would like use some of the GD image functions, so I ran a couple of
> short scripts to see if it worked, such as:
>
> <?php
>
> /* Create a red square */
> $image = imagecreate(200, 200);
> $colorRed = imagecolorallocate($image, 255, 0, 0);
> imagefill($image, 0, 0, $colorRed);
>
> //send image
> header("Content-type: image/jpeg");
> imagejpeg($image);
>
> ?>
>
> but all they generates are garbage characters and no image, starting
> with:
> ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default
> quality ÿÛC ... (etc.)
>
> I then ran a script to see what version was installed
> (var_dump(gd_info());)and it generated: ["GD Version"]=> string(24)
> "bundled (2.0 compatible)"
>
>
> So why doesn't it generate a jpeg? Am I doing something incorrectly or
> is it the library itself? (This is using a hosting account at
> godaddy.com. It is not PHP or a GD library that I installed).
>
> Thanks,
> Eric
>


Copied your script to my server and it worked just fine... you really
don't even need the 'header...' line either...

<?PHP
$image = imagecreate(200, 200);
$colorRed = imagecolorallocate($image, 255, 0, 0);
imagefill($image, 0, 0, $colorRed);

//send image
//header("Content-type: image/jpeg");
imagejpeg($image);
?>

here is a link: http://www.suddenimpactfans.com/getphoto3.php

It could be a problem on your host side - although the only time I get text
output from the GD stuff is if there is an error in one of the function
calls...



Reply With Quote
  #4 (permalink)  
Old 01-03-2004
Randell D.
 
Posts: n/a
Default Re: Using GD Library Functions


"SwissCheese" <SwissCheese@cfl.rr.com> wrote in message
news:F8pJb.106171$Dt6.3022284@twister.tampabay.rr. com...
"Uncle_Alias" <zephinilium@yahoo.com> wrote in message
news:e1eff209.0401021505.12133746@posting.google.c om...
> I would like use some of the GD image functions, so I ran a couple of
> short scripts to see if it worked, such as:
>
> <?php
>
> /* Create a red square */
> $image = imagecreate(200, 200);
> $colorRed = imagecolorallocate($image, 255, 0, 0);
> imagefill($image, 0, 0, $colorRed);
>
> //send image
> header("Content-type: image/jpeg");
> imagejpeg($image);
>
> ?>
>
> but all they generates are garbage characters and no image, starting
> with:
> ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default
> quality ÿÛC ... (etc.)
>
> I then ran a script to see what version was installed
> (var_dump(gd_info());)and it generated: ["GD Version"]=> string(24)
> "bundled (2.0 compatible)"
>
>
> So why doesn't it generate a jpeg? Am I doing something incorrectly or
> is it the library itself? (This is using a hosting account at
> godaddy.com. It is not PHP or a GD library that I installed).
>
> Thanks,
> Eric
>


Copied your script to my server and it worked just fine... you really
don't even need the 'header...' line either...

<?PHP
$image = imagecreate(200, 200);
$colorRed = imagecolorallocate($image, 255, 0, 0);
imagefill($image, 0, 0, $colorRed);

//send image
//header("Content-type: image/jpeg");
imagejpeg($image);
?>

here is a link: http://www.suddenimpactfans.com/getphoto3.php

It could be a problem on your host side - although the only time I get text
output from the GD stuff is if there is an error in one of the function
calls...



--
====================================

Eric,

I'm just wondering if its a header problem.... Make sure you have no spaces
before your <?PHP tag...

If you want to see what type of GD support you have, try
<?
$gdinfo=gd_info();
foreach($gd_info as $key=>$element)
{
print("<br>$key = $element");
}
?>

laters
Randell D.


Reply With Quote
  #5 (permalink)  
Old 01-03-2004
Tim Van Wassenhove
 
Posts: n/a
Default Re: Using GD Library Functions

On 2004-01-03, Randell D. <reply.to.news.group.only@and.share.com> wrote:
>
> "SwissCheese" <SwissCheese@cfl.rr.com> wrote in message
> news:F8pJb.106171$Dt6.3022284@twister.tampabay.rr. com...
> "Uncle_Alias" <zephinilium@yahoo.com> wrote in message
> news:e1eff209.0401021505.12133746@posting.google.c om...
>> I would like use some of the GD image functions, so I ran a couple of
>> short scripts to see if it worked, such as:
>>
>> <?php
>>
>> /* Create a red square */
>> $image = imagecreate(200, 200);
>> $colorRed = imagecolorallocate($image, 255, 0, 0);
>> imagefill($image, 0, 0, $colorRed);
>>
>> //send image
>> header("Content-type: image/jpeg");
>> imagejpeg($image);
>>
>> ?>
>>
>> but all they generates are garbage characters and no image, starting
>> with:
>> ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default
>> quality ÿÛC ... (etc.)
>>
>> I then ran a script to see what version was installed
>> (var_dump(gd_info());)and it generated: ["GD Version"]=> string(24)
>> "bundled (2.0 compatible)"
>>
>>
>> So why doesn't it generate a jpeg? Am I doing something incorrectly or
>> is it the library itself? (This is using a hosting account at
>> godaddy.com. It is not PHP or a GD library that I installed).
>>
>> Thanks,
>> Eric
>>

>
> Copied your script to my server and it worked just fine... you really
> don't even need the 'header...' line either...
>
><?PHP
> $image = imagecreate(200, 200);
> $colorRed = imagecolorallocate($image, 255, 0, 0);
> imagefill($image, 0, 0, $colorRed);
>
> //send image
> //header("Content-type: image/jpeg");
> imagejpeg($image);
> ?>
>
> here is a link: http://www.suddenimpactfans.com/getphoto3.php
>
> It could be a problem on your host side - although the only time I get text
> output from the GD stuff is if there is an error in one of the function
> calls...


When using Mozilla/1.6b/Win32 i get some scrambled text.
When using InternetExplorer/6.1/Win32 i get a red square.


--
verum ipsum factum
Reply With Quote
  #6 (permalink)  
Old 01-03-2004
Uncle_Alias
 
Posts: n/a
Default Re: Using GD Library Functions

"Randell D." <reply.to.news.group.only@and.share.com> wrote in message news:<RPpJb.917448$pl3.238882@pd7tw3no>...
....

>
> Eric,
>
> I'm just wondering if its a header problem.... Make sure you have no spaces
> before your <?PHP tag...
>
> If you want to see what type of GD support you have, try
> <?
> $gdinfo=gd_info();
> foreach($gd_info as $key=>$element)
> {
> print("<br>$key = $element");
> }
> ?>
>
> laters
> Randell D.



Aha! That was it: I moved the PHP code to before the <html> tag - I
had it in the body. Now it works.
So tell this newbie: why does this PHP code need to not be in the
<body> section? Other PHP code I've run has worked fine in the body.

Thanks,
Eric

BTW I couldn't get your GD support check code to work. <scratch head>
Reply With Quote
  #7 (permalink)  
Old 01-03-2004
CountScubula
 
Posts: n/a
Default Re: Using GD Library Functions

http://gzen.myhq.info -- free online php tools
"Uncle_Alias" <zephinilium@yahoo.com> wrote in message
news:e1eff209.0401030024.514f815@posting.google.co m...
> "Randell D." <reply.to.news.group.only@and.share.com> wrote in message

news:<RPpJb.917448$pl3.238882@pd7tw3no>...
> ...
>
> >
> > Eric,
> >
> > I'm just wondering if its a header problem.... Make sure you have no

spaces
> > before your <?PHP tag...
> >
> > If you want to see what type of GD support you have, try
> > <?
> > $gdinfo=gd_info();
> > foreach($gd_info as $key=>$element)
> > {
> > print("<br>$key = $element");
> > }
> > ?>
> >
> > laters
> > Randell D.

>
>
> Aha! That was it: I moved the PHP code to before the <html> tag - I
> had it in the body. Now it works.
> So tell this newbie: why does this PHP code need to not be in the
> <body> section? Other PHP code I've run has worked fine in the body.
>
> Thanks,
> Eric
>
> BTW I couldn't get your GD support check code to work. <scratch head>


there should bo NO body section, we (i assume everyone else here) thought
that was your complete script.

you are to send out a <BODY> tag if you are sending out an .html page,
becouse html pages continain, a body.

when you are sending out image data, send out only image data.

Think of it not as html with php in it, but rather a scripting lanugage
thats send out plain data outside the <?php ?> tags

so, with this line of though, php can send out any type of data. in fact
some people (myself included) dont have any text outside the <?php ?> tags,
and use it soley as a scripting laguage.

now, if a script needed to send, lets say the <HTML> tag, 2 ways

<HTML>
<?php
some script....
?>
</HTML>

or

<?php
print "<HTML>\n";
some script...
print "</HTML>\n";
?>

so you see, anything outside the <?php ?> tags is send directly to the
browser.



--
Mike Bradley



Reply With Quote
  #8 (permalink)  
Old 01-03-2004
tom
 
Posts: n/a
Default Re: Using GD Library Functions

Randell D. wrote:
> "SwissCheese" <SwissCheese@cfl.rr.com> wrote in message
> news:F8pJb.106171$Dt6.3022284@twister.tampabay.rr. com...
> "Uncle_Alias" <zephinilium@yahoo.com> wrote in message
> news:e1eff209.0401021505.12133746@posting.google.c om...
>> I would like use some of the GD image functions, so I ran a couple of
>> short scripts to see if it worked, such as:
>>
>> <?php
>>
>> /* Create a red square */
>> $image = imagecreate(200, 200);
>> $colorRed = imagecolorallocate($image, 255, 0, 0);
>> imagefill($image, 0, 0, $colorRed);
>>
>> //send image
>> header("Content-type: image/jpeg");
>> imagejpeg($image);
>>
>> ?>
>>
>> but all they generates are garbage characters and no image, starting
>> with:
>> ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default
>> quality ÿÛC ... (etc.)
>>
>> I then ran a script to see what version was installed
>> (var_dump(gd_info());)and it generated: ["GD Version"]=> string(24)
>> "bundled (2.0 compatible)"
>>
>>
>> So why doesn't it generate a jpeg? Am I doing something incorrectly or
>> is it the library itself? (This is using a hosting account at
>> godaddy.com. It is not PHP or a GD library that I installed).
>> Thanks,
>> Eric
>>

>
> Copied your script to my server and it worked just fine... you really
> don't even need the 'header...' line either...
>
> <?PHP
> $image = imagecreate(200, 200);
> $colorRed = imagecolorallocate($image, 255, 0, 0);
> imagefill($image, 0, 0, $colorRed);
>
> //send image
> //header("Content-type: image/jpeg");
> imagejpeg($image);
> ?>
>
> here is a link: http://www.suddenimpactfans.com/getphoto3.php
>
> It could be a problem on your host side - although the only time I get
> text output from the GD stuff is if there is an error in one of the
> function calls...


help - I see loadsa junk on konqueror, and a few lines of junk with netscape
thanks, tom
Reply With Quote
  #9 (permalink)  
Old 01-03-2004
SwissCheese
 
Posts: n/a
Default Re: Using GD Library Functions


"tom" <test@nospam.com> wrote in message
news:bt67p0$hir$2$8300dec7@news.demon.co.uk...
> Randell D. wrote:
> > "SwissCheese" <SwissCheese@cfl.rr.com> wrote in message
> > news:F8pJb.106171$Dt6.3022284@twister.tampabay.rr. com...
> > "Uncle_Alias" <zephinilium@yahoo.com> wrote in message
> > news:e1eff209.0401021505.12133746@posting.google.c om...
> >> I would like use some of the GD image functions, so I ran a couple of
> >> short scripts to see if it worked, such as:
> >>
> >> <?php
> >>
> >> /* Create a red square */
> >> $image = imagecreate(200, 200);
> >> $colorRed = imagecolorallocate($image, 255, 0, 0);
> >> imagefill($image, 0, 0, $colorRed);
> >>
> >> //send image
> >> header("Content-type: image/jpeg");
> >> imagejpeg($image);
> >>
> >> ?>
> >>
> >> but all they generates are garbage characters and no image, starting
> >> with:
> >> ÿØÿàJFIFÿþ>CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), default
> >> quality ÿÛC ... (etc.)
> >>
> >> I then ran a script to see what version was installed
> >> (var_dump(gd_info());)and it generated: ["GD Version"]=> string(24)
> >> "bundled (2.0 compatible)"
> >>
> >>
> >> So why doesn't it generate a jpeg? Am I doing something incorrectly or
> >> is it the library itself? (This is using a hosting account at
> >> godaddy.com. It is not PHP or a GD library that I installed).
> >> Thanks,
> >> Eric
> >>

> >
> > Copied your script to my server and it worked just fine... you really
> > don't even need the 'header...' line either...
> >
> > <?PHP
> > $image = imagecreate(200, 200);
> > $colorRed = imagecolorallocate($image, 255, 0, 0);
> > imagefill($image, 0, 0, $colorRed);
> >
> > //send image
> > //header("Content-type: image/jpeg");
> > imagejpeg($image);
> > ?>
> >
> > here is a link: http://www.suddenimpactfans.com/getphoto3.php
> >
> > It could be a problem on your host side - although the only time I get
> > text output from the GD stuff is if there is an error in one of the
> > function calls...

>
> help - I see loadsa junk on konqueror, and a few lines of junk with

netscape
> thanks, tom
>


Try it now - I enabled the header line as Opera 7+ gave junk too, but now
doesn't with the header line.


Reply With Quote
  #10 (permalink)  
Old 01-04-2004
Randell D.
 
Posts: n/a
Default Re: Using GD Library Functions


"Randell D." <reply.to.news.group.only@and.share.com> wrote in message
news:<RPpJb.917448$pl3.238882@pd7tw3no>...
> If you want to see what type of GD support you have, try
> <?
> $gdinfo=gd_info();
> foreach($gd_info as $key=>$element)
> {
> print("<br>$key = $element");
> }
> ?>
>
> laters
> Randell D.



Aha! That was it: I moved the PHP code to before the <html> tag - I
had it in the body. Now it works.
So tell this newbie: why does this PHP code need to not be in the
<body> section? Other PHP code I've run has worked fine in the body.

Thanks,
Eric

BTW I couldn't get your GD support check code to work. <scratch head>


--
====================================
Hi again,
I don't know why you couldn't get the above code to work... take a look at
http://ca3.php.net/manual/en/function.gd-info.php

If will tell you what functionality the gdlib can give you (this can vary
pending what libraries you have installed). The gd_info() function should
work on any PHP 4 forward...

If that doesn't work, try phpinfo(); and examine any mention of GD in its
output...

Lastly... when outputing an image, it is handled differently by the web
client than when sending text... It has to do with headers... this might be
the reason as to why you are getting mixed results from browser to
browser... Some browsers might attempt to be intelligent and guess what data
is being sent to them, while othes will just display the binary data that
makes up the image (aka junk to you and I). I would suggest that you write
your test image to a file first, then have your HTML request the image with
the html <img> tag.... Once you've solved that, then I'd go one step further
to work on dynamic images if that's your thing...

Replies please... via the newsgroup, so everyone can learn... and happy new
year,
Thanks,
Randell D.


Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 06:50 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0