This is a discussion on Problem with simple image generation script within the PHP Language forums, part of the PHP Programming Forums category; Hi, I am using the following code to generate images online: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4....
|
|||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
Hi,
I am using the following code to generate images online: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php //set up image $height = 200; $width = 200; $im = ImageCreate($width, $height); $white = ImageColorAllocate ($im, 255, 255, 255); $black = ImageColorAllocate ($im, 0, 0, 0); //draw on image ImageFill($im, 0, 0, $black); ImageLine($im, 0, 0, $height, $width, $black); ImageString($im, 4, 50, 150, "Sales", $white); //output image Header("Content-type: image/png"); ImagePng ($im); //clean up ImageDestroy($im); ?></body> </html> Unfortunetely I am getting the following error message: Warning: Cannot modify header information - headers already sent by (output started at /data/httpd/VirtualHosts/webdev/htdocs/mb_sandbox/_test/img_gen01.php:9) in /data/httpd/VirtualHosts/webdev/htdocs/mb_sandbox/_test/img_gen01.php on line 24 ‰PNG IHDRÈÈ—–<ÝPLTEÿÿÿUÂÓ~aIDATxœ*α €0Cьʉò*¬Êw(e"% *Hß*“l§±JBAAAä+‰Q⥽—hR ª›ç¢¤÷GôëÓ®Cïdó!Û|7w)qo‹o"‚ü_& ÝekaÛúIEND®B`‚ My guess if that it is failing to create the header so therefor the jumbled mess is the image data but without the browser knowing that. I know that the img gen software is installed on the server because there are scripts already running this. Any help? Cheers Burnsy |
|
|||
|
Burnsy:
> My guess if that it is failing to create the header so therefor the > jumbled mess is the image data but without the browser knowing that. I > know that the img gen software is installed on the server because there > are scripts already running this. Any help? Your problem is that you are trying to output an image directly into html. Move all the image generation stuff to a new file and call it within the html document as an image. Mike |
|
|||
|
On 17 May 2005 08:15:16 -0700, bissatch@yahoo.co.uk wrote:
> Warning: Cannot modify header information - headers already sent Yes, files have headers, and your html file already got some. So your img generating script needs to be a separate file, for example: <img src="makeimg.php?x=200&y=100" /> (you could use get variables as img parameters) and then in makeimg.php the php code you already wrote, including the header() call. -- Firefox Web Browser - Rediscover the web - http://getffox.com/ Thunderbird E-mail and Newsgroups - http://gettbird.com/ |
|
|||
|
By the way - anyone know of a handy script that works like the
ficticious makeimg.php above but also has the added functionality to: 1. when queried, check whether the thumbnail exists 2. if it doesn't exist, create a thumbnail out of an original image thanks, kalen |
|
|||
|
kjordan@insurancejournal.com wrote:
> By the way - anyone know of a handy script that works like the > ficticious makeimg.php above but also has the added functionality to: > > 1. when queried, check whether the thumbnail exists > 2. if it doesn't exist, create a thumbnail out of an original image > Come on, dude! If you're semi-competent at PHP, that shouldn't take much trouble to knock together yourself. if (file_exists($thumb_filename)) { /* read out image file */ } else { if (file_exists($original_filename)) { /* load file using imagecreatefromjpeg() or whatever */ /* create blank image at desired thumbnail size */ /* imagecopyresampled() */ /* save file */ /* read out image file */ } } -- Oli |
|
|||
|
hey man, there's no need to slap a guy in the face with a bunch of
pseudocode that he could have spit out himself when all he's asking for is a php snippet that could save him a couple hours that he doesn't plan on spending himself any time soon. thanks anyway, i guess. and what's wrong with a good old fashioned "elseif"? |
|
|||
|
kjordan@insurancejournal.com wrote:
> hey man, there's no need to slap a guy in the face with a bunch of > pseudocode that he could have spit out himself when all he's asking for > is a php snippet that could save him a couple hours that he doesn't > plan on spending himself any time soon. > Sorry, I didn't mean to get all elitist on you. However, if you're able to write the pseudo-code yourself, you should know that to convert it to real code it's basically just a matter of filling in the blanks, which shouldn't take a couple of hours (hopefully!). Besides, even if someone gave you an actual code snippet, you'd still have to spend time customising it to suit your needs (i.e. input variable criteria, image resizing, format, directory structure, etc.) > thanks anyway, i guess. and what's wrong with a good old fashioned > "elseif"? Nothing, I just hardly ever seem to use it for some reason... -- Oli |