image problems

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

image problems

Post by psychotomus »

Code: Select all

<?php

$srcimg = imagecreatefromjpeg ("./otwanted.jpg") or die ("Problem In opening Source Image");  // For JPEG 
$textcolor = imagecolorallocate($srcimg, 0, 0, 255); 
imagestring($srcimg, 5, 0, 0, $_GET['caption'], $textcolor);
header("Content-type: image/jpeg");
imagejpeg($srcimg); 
exit();
?>
doesn't print the image but the source of the image.
http://po2shoutbox.com/test1.php look.
basdog22
Forum Contributor
Posts: 158
Joined: Sun Nov 30, 2003 3:03 pm
Location: Greece

Post by basdog22 »

If you turn error reporting on ( error_reporting(E_ALL); ) you will see some errors like:

Headers already sent by....

This means that when you use the header(); function there must be no output before this function. Try doing the same script without the form :wink:
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

i get the same error if i put the form below the php code.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

anybody?
User avatar
IceMetalPunk
Forum Commoner
Posts: 71
Joined: Thu Jul 07, 2005 11:45 am

Post by IceMetalPunk »

I'm not sure, but try changing

Code: Select all

header("Content-type: image/jpeg");
To this:

Code: Select all

header("Content-type: image/jpg");
-IMP ;) :)
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

You can't output HTML markup and an image on the same request. You can output one or the other but not both.
User avatar
IceMetalPunk
Forum Commoner
Posts: 71
Joined: Thu Jul 07, 2005 11:45 am

Post by IceMetalPunk »

Who's outputting HTML?

-IMP ;) :)
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

IceMetalPunk wrote:Who's outputting HTML?

-IMP ;) :)
try visiting the OP's link
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

do I need the header?
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

bokehman wrote:You can't output HTML markup and an image on the same request. You can output one or the other but not both.
then how do i output HTML and an image???
User avatar
dull1554
Forum Regular
Posts: 680
Joined: Sat Nov 22, 2003 11:26 am
Location: 42:21:35.359N, 76:02:20.688W

Post by dull1554 »

you will have your php script to generate your image
example: image.php

then you will have a page that outputs html

exa,ple: index.php

call your image like this

<img src="img/image.php" />
User avatar
bokehman
Forum Regular
Posts: 509
Joined: Wed May 11, 2005 2:33 am
Location: Alicante (Spain)

Post by bokehman »

psychotomus wrote:
bokehman wrote:You can't output HTML markup and an image on the same request. You can output one or the other but not both.
then how do i output HTML and an image???
On separate requests. Each item on a website is retrieved through an individual request to the server... So if a document is made up of an HTML string and two images, altogether three requests will be sent to the server from the client's browser. An yes... you do need a mime header. It tells the web browser what the content is so it know how to display it.
User avatar
Ollie Saunders
DevNet Master
Posts: 3179
Joined: Tue May 24, 2005 6:01 pm
Location: UK

Post by Ollie Saunders »

the content-type header isn't being sent (see)

As there are no configuration directives for header() in PHP that might prevent it from working I'd look to problems with your webserver. Ah I've just noticed that your server is sending a server header of "Servage.net Cluster (Enhanced Apache)". What exactly is that?

You might want to check there isn't some kind of limitation the webserver is imposing on PHP or that header() is even compatable with your webserver.
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

Post by psychotomus »

How Can I change the Text Properties when placing text on the image such as the Height?
Post Reply