Problem with simple image generation script

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....


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-17-2005
bissatch@yahoo.co.uk
 
Posts: n/a
Default Problem with simple image generation script

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

Reply With Quote
  #2 (permalink)  
Old 05-17-2005
Mike Willbanks
 
Posts: n/a
Default Re: Problem with simple image generation script

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
Reply With Quote
  #3 (permalink)  
Old 05-17-2005
Ewoud Dronkert
 
Posts: n/a
Default Re: Problem with simple image generation script

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/
Reply With Quote
  #4 (permalink)  
Old 05-17-2005
kjordan@insurancejournal.com
 
Posts: n/a
Default Re: Problem with simple image generation script

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

Reply With Quote
  #5 (permalink)  
Old 05-18-2005
Oli Filth
 
Posts: n/a
Default Re: Problem with simple image generation script

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

Reply With Quote
  #6 (permalink)  
Old 05-18-2005
kjordan@insurancejournal.com
 
Posts: n/a
Default Re: Problem with simple image generation script

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"?

Reply With Quote
  #7 (permalink)  
Old 05-18-2005
Oli Filth
 
Posts: n/a
Default Re: Problem with simple image generation script

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

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 11:31 AM.


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