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 ...
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
"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... |
|
|||
|
"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. |
|
|||
|
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 |
|
|||
|
"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> |
|
|||
|
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 |
|
|||
|
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 |
|
|||
|
"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. |
|
|||
|
"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. |