Page 1 of 1

DIsplaying an Image

Posted: Sat Apr 10, 2004 12:53 pm
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);
?>

Posted: Sat Apr 10, 2004 1:16 pm
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.

Posted: Sat Apr 10, 2004 1:49 pm
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.

Posted: Sat Apr 10, 2004 5:51 pm
by vigge89
just use the $_POST/$_GET variables....

Posted: Sat Apr 10, 2004 6:01 pm
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.

Posted: Sat Apr 10, 2004 6:05 pm
by markl999
Could you show what you put in image.php to cause it to 'break' ?

Posted: Sat Apr 10, 2004 6:23 pm
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?

Posted: Sun Apr 11, 2004 4:46 am
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...