DIsplaying an Image

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
JohnDigweed
Forum Newbie
Posts: 18
Joined: Sun Mar 28, 2004 6:24 pm
Location: root/user/hell

DIsplaying an Image

Post by JohnDigweed »

Hi,

I used the image functions in PHP to make an image. What I did was I made it a file called image.php. The text on the image is based on information submitted in a form.

In my other PHP document, show.php, i used html. Inside the html table, I placed <? include "image.php"; ?>

However, when I view show.php, all I see is a bunch of random code with a bunch of different foregn letters inside the html table.

Why does it do this, and how would I display the image inside the table?

Could this have to do with destroying the image?

Normally if i vew Image.php it looks normal. THe image shows up perfect!

Here is the code for image.php :

Code: Select all

<?php
header("Content-type: image/png");
$im = imagecreatefrompng("path/to/imgae");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, $cc&#1111;0], $cc&#1111;1], $cc&#1111;2]);
imagettftext($im, $companysize, 0, 70, 40, $text_color, $companyfont,
  $companytext);
imagepng($im);
imagedestroy($im);
?>
User avatar
wwwapu
Forum Contributor
Posts: 197
Joined: Wed Apr 07, 2004 11:57 am
Location: Turku, Finland

Post by wwwapu »

Hi.
You could try NOT to include() your picture, but use img element. I tested this just now and the results are below:

Code: Select all

<html>
<head>
<title>Testi1</title>
</head>
<body>
<?php
include("kuva2.php");
?>
</body>
</html>
This shows html source:

Code: Select all

<html>
<head>
<title>Testi</title>
</head>
<body>
ÿØÿà
ÿÛ

But when using img element everything works just fine.

Code: Select all

<html>
<head>
<title>Testi2</title>
</head>
<body>

<img src="kuva2.php" alt="picture">

</body>
</html>
Hopefully this is what you needed.
JohnDigweed
Forum Newbie
Posts: 18
Joined: Sun Mar 28, 2004 6:24 pm
Location: root/user/hell

Post by JohnDigweed »

Hi

Thanks for that, but this is the thing.

I have a form that goes to image.php.

What was typed in the form shows on up on the image made in image.php. So, I need the variables to pass through image.php

However, I need the image made in image.php using the variables to also be displayed in show.php


Using the IMG tag will only display a blank image, because the variables havent passed to image.php. Thats why I was trying to use include. Is there any other way to do this?

Hope this is clear.
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

just use the $_POST/$_GET variables....
JohnDigweed
Forum Newbie
Posts: 18
Joined: Sun Mar 28, 2004 6:24 pm
Location: root/user/hell

Post by JohnDigweed »

Yes,

I am using that. image.php gets those variables and uses that to post on an image. That isnt the problem. The problem is, I want to use that image and place it in the middle of a table I made, with a heading. When I have ANYTHING other than the image code in image.php, the image scrambles into foreign letters. Im not sure if the headers are wrong?

Thanks.
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

Could you show what you put in image.php to cause it to 'break' ?
JohnDigweed
Forum Newbie
Posts: 18
Joined: Sun Mar 28, 2004 6:24 pm
Location: root/user/hell

Post by JohnDigweed »

Hi,

Thanks for the reply. The problem isnt in Image.php, its in show.php. However, I will post it :

Code: Select all

<?php
header ("Content-Transfer-Encoding: binary");
header ("Content-type: image/png");
header ("Content-length: 10000");
$company = $_POST&#1111;'company'];
$companycolor = $_POST&#1111;'companycolor'];
$companyfont = $_POST&#1111;'companyfont'];
$companysize = $_POST&#1111;'companysize'];
$cc = explode(" ", $companycolor);

$im = imagecreatefrompng("path/to/png");
$background_color = imagecolorallocate($im, 255, 255, 255);
$text_color = imagecolorallocate($im, $cc&#1111;0], $cc&#1111;1], $cc&#1111;2]);
imagettftext($im, $companysize, 0, 70, 40, $text_color, $companyfont,
  $company);
imagepng($im);
imagedestroy($im);
?>
I want to include that image in show.php. How would I do so?
User avatar
vigge89
Forum Regular
Posts: 875
Joined: Wed Jul 30, 2003 3:29 am
Location: Sweden

Post by vigge89 »

<img src='image.php' alt='image' />

you can't include the PHP code, becuase if you would, PHP would justexecute it and output 'headers already sent', and the PNG-output...
Post Reply