This is a discussion on Using GD Library Functions within the PHP Language forums, part of the PHP Programming Forums category; "CountScubula" <me@scantek.hotmail.com> wrote in message news:<KDvJb.4901$Ci5.2352@newssvr27.news....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
"CountScubula" <me@scantek.hotmail.com> wrote in message news:<KDvJb.4901$Ci5.2352@newssvr27.news.prodigy.c om>...
> > 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. Interesting. OK, and I find out from the php.net site that for the imagejpeg() function that "The filename argument is optional, and if left off, the raw image stream will be output directly." (http://www.php.net/manual/en/function.imagejpeg.php) So that's why one gets either text garbage or an image and nothing else - it's just an image that's output DIRECTLY to the browser. So... if I wanted to create the image and have my cake and eat it too, I could (supposedly) save it and then display it with an HTML image tag, like: <html> <head> <title>Listing 12-2a</title> </head> <body> <?php /* Create a red square */ $image = imagecreate(200, 200); $colorRed = imagecolorallocate($image, 255, 0, 0); imagefill($image, 0, 0, $colorRed); //save image then use later imagejpeg($image, "pic.jpg"); imagedestroy($image); ?> <img src="pic.jpg" border=0> <br>Here is some text. </body> </html> Well, I tried this but it can't find (doesn't display) the image. Where'd it go? I looked in my hosting account directories but couldn't find it anywhere. I assumed it would appear in the directory where the PHP script was run. |
|
|||
|
On 2004-01-04, Uncle_Alias <zephinilium@yahoo.com> wrote:
><?php > /* Create a red square */ > $image = imagecreate(200, 200); > $colorRed = imagecolorallocate($image, 255, 0, 0); > imagefill($image, 0, 0, $colorRed); > > //save image then use later > imagejpeg($image, "pic.jpg"); > imagedestroy($image); > ?> > ><img src="pic.jpg" border=0> ><br>Here is some text. ></body> ></html> > > > Well, I tried this but it can't find (doesn't display) the image. > Where'd it go? I looked in my hosting account directories but couldn't > find it anywhere. I assumed it would appear in the directory where the > PHP script was run. This way, you need to make sure that the user which is running apache/php (usually nobody or www-data) has the rights to write such a file at that place. -- verum ipsum factum |
|
|||
|
Tim Van Wassenhove wrote:
> On 2004-01-04, Uncle_Alias <zephinilium@yahoo.com> wrote: > >> <?php >> /* Create a red square */ >> $image = imagecreate(200, 200); >> $colorRed = imagecolorallocate($image, 255, 0, 0); >> imagefill($image, 0, 0, $colorRed); >> >> //save image then use later >> imagejpeg($image, "pic.jpg"); >> imagedestroy($image); >>> >> >> <img src="pic.jpg" border=0> >> <br>Here is some text. >> </body> >> </html> >> >> >> Well, I tried this but it can't find (doesn't display) the image. >> Where'd it go? I looked in my hosting account directories but >> couldn't find it anywhere. I assumed it would appear in the >> directory where the PHP script was run. > > This way, you need to make sure that the user which is running > apache/php (usually nobody or www-data) has the rights to write such a > file at that place. What tim said. Also, note that if you have a page that's something like: <?php // this file is somepage.php header(stuff for jpeg); // too lazy to remember syntax .... imagejpeg($img); ?> you can do <img src="somepage.php"> |
|
|||
|
SwissCheese wrote:
> > "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. worked - thanks (I still get this on my server though - and need to keep at it), tom |
|
|||
|
"Agelmar" <ifetteNOSPAM@comcast.net> wrote in message news:<bt87nl$4bnnn$1@ID-30799.news.uni-berlin.de>...
> Tim Van Wassenhove wrote: > > On 2004-01-04, Uncle_Alias <zephinilium@yahoo.com> wrote: > > > >> <?php > >> /* Create a red square */ > >> $image = imagecreate(200, 200); > >> $colorRed = imagecolorallocate($image, 255, 0, 0); > >> imagefill($image, 0, 0, $colorRed); > >> > >> //save image then use later > >> imagejpeg($image, "pic.jpg"); > >> imagedestroy($image); > >>> > >> > >> <img src="pic.jpg" border=0> > >> <br>Here is some text. > >> </body> > >> </html> > >> > >> > >> Well, I tried this but it can't find (doesn't display) the image. > >> Where'd it go? I looked in my hosting account directories but > >> couldn't find it anywhere. I assumed it would appear in the > >> directory where the PHP script was run. > > > > This way, you need to make sure that the user which is running > > apache/php (usually nobody or www-data) has the rights to write such a > > file at that place. > > What tim said. > > Also, note that if you have a page that's something like: > <?php > // this file is somepage.php > header(stuff for jpeg); // too lazy to remember syntax > ... > imagejpeg($img); > ?> > > you can do > <img src="somepage.php"> Yeah, that works. Cool. Raises all kinds of possibilities... |
|
|||
|
"Randell D." <reply.to.news.group.only@and.share.com> wrote in message news:<%NIJb.931853$pl3.509732@pd7tw3no>...
> > -- > ==================================== > 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. phpinfo(); is disabled in the configuration of PHP at my hosting account. I guess they don't want people hacking it?: "The following functions have been disabled on our Unix servers: fpassthru file exec system passthru popen crack_check crack_closedict crack_getlastmessage crack_opendict fsockopen psockopen opendir readdir closedir phpinfo all Posix functions" Maybe this explains why gd_info() doesn't work. (It is PHP 4.3.1 BTW). Funny thing is, I used the mail function in a small script, and it worked. Go figure. Eric |