473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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

Jul 17 '05 #1
6 2547
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
Jul 17 '05 #2
On 17 May 2005 08:15:16 -0700, bi******@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/
Jul 17 '05 #3
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

Jul 17 '05 #4
kj*****@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

Jul 17 '05 #5
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"?

Jul 17 '05 #6
kj*****@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

Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: OneSolution | last post by:
Hi All, Here's what I'm trying to do. I have a diverse customer base, and as it grows, it's increasingly harder to figure out what aspect of our web site is selling and what is not. So I've...
1
by: Preston Crawford | last post by:
I'm looking to quickly get a photo album online. Very simple, thumbnails, a few pages, maybe a description, but hopefully a small script that's easy to edit and work into my existing site. I know...
5
by: Shawn Hamzee | last post by:
Hello All, I am having a problem with Image_Graph on php 5.1.4. I installed the package and all of its dependencies through pear installer without any hitches. Then I started to add some very...
1
by: www.web20developers.com | last post by:
http://www.web20developers.com http://www.web20developers.com/index.php?option=com_content&task=view... Ajallerix : AJAX, simple, fast Web image gallery demo ; at Novell AJAX -...
0
by: Adam Sandler | last post by:
Hello, Having an issue with my ASP.Net page. I use some COTS, which for all intents and purposes, simply makes a jpeg file and physically places it in a directory on the web server. The...
11
by: Adam Sandler | last post by:
Hello, Having an issue with JavaScript in my ASP.Net page. I use some COTS, which for all intents and purposes, simply makes a jpeg file and physically places it in a directory on the web...
3
by: modermo | last post by:
Hey new to javascript figuring out how to fix this darn problem. I employ an image rollover, and it works beautifully in safari. But in firefox, the image has an annoying blue border around...
4
by: STIAdmin | last post by:
Happy Holidays to all of you! This is my first time posting. I'm working on a web project and trying to get this done before Christmas. The limitation is that I'm using an out of the box program...
2
by: swethak | last post by:
Hi, I am getting the problem the problem with google map in Internet Explorer. This map worked fine in mozilla . When i opened the same map in Internet Explorer i am getting the error...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.