Forum Moderators: coopster

Message Too Old, No Replies

Problems Displaying Images

Cannot generate two images at the same time

         

hwttdz

12:17 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



I'm trying to use a bit of php script to display two images but for some reason it's not working as I think it should. I have a file called imgtest3.php and if I call up imgtest3.php?type=1 or imgtest3.php?type=2 in my browser I get the correct image. If I have

texttest3.php


<?php
ini_set("display_errors", "On");
echo("this is text before the picture <br>");
?>
<IMG SRC="imgtest3.php?type=1">
<IMG SRC="imgtest3.php?type=2">
<br>
<?php
echo("this is text after the picture");

?>


It no longer works. I've been working on this for a while and can't figure anything out. If I set both of the types to the same number in texttest3.php it works without any problems. Any ideas? Is passing a get parameter the best way to change the output when you call the same code twice?

hakre

1:42 pm on Jun 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hi hwttdz,

i can not tell you why it's not working, but i think too that it should. maybe the file displayed then, does not work. simply put the url of the image which makes problems directly into your browsers adress textfield and check it out by hand.

-hakre

hwttdz

1:48 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



I think what you're suggesting is to put

localhost/imgtest3.php?type=1 or localhost/imgtest3.php?type=2
both of these work exactly as they should.

The display I get sometimes displays part of the images, usually just a bit at the top then some sort of static looking stuff then it goes all black. Sometimes I get an apache server error as well.

Sathallrin

2:11 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



Is imgtest3.php actually creating an image file.. by using something like:
header("Content-type: image/gif");

If it is not creating an image, but rather outputing HTML to display an image, then you cannot put the url in the src part of an img tag.

hwttdz

2:17 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



Yes, it's creating an image, it displays correctly if I only have one <img src= or if I set the type on both to the same number.

hakre

2:21 pm on Jun 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



how does the php script create / passthru the image data? can you specify a bit more? i assume that with the parameter where no image is displayed the script does not work because it's a wrong value.

hwttdz

2:42 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



texttest3.php

<?php
ini_set("display_errors", "On");
echo("this is text before the picture <br>");
?>
<IMG SRC="imgtest3.php?type=1">
<IMG SRC="imgtest3.php?type=2">
<br>
<?php
echo("this is text after the picture");
?>

imgtest3.php

<?php
//start of main
header("Content-type: image/gif");
ini_set("display_errors", "On");
$link = @mysql_connect('localhost', 'user', 'mypass')
or die("Could not connect to MySQL");
$db = @mysql_select_db('temp2',$link)
or die("Could not select database");
$type=$_GET['type'];
$image=drawimage($link,$type);
imagegif($image);
//end of main
function drawimage($link,$type)
{
if($type==1)$image = imagecreatefromgif("map.gif");
if($type==2)$image = imagecreatefromgif("map2.gif");

$query = "SELECT * FROM table2ll WHERE status=1"; //select green sites
$result = @mysql_query($query,$link) or die("Could not submit query1");
makedots($image, $result, 1);

$query = "SELECT * FROM table2ll WHERE status=2";//select red sites
$result = @mysql_query($query,$link) or die("Could not submit query");
makedots($image, $result,2);

$query = "SELECT * FROM table2ll WHERE status=3";//select clear sites
$result = @mysql_query($query,$link) or die("Could not submit query");
makedots($image, $result,3);
return($image);
}

Sathallrin

3:21 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



I tried that on my server without the SQL stuff (since i don't have your DB)

<?php
//start of main
header("Content-type: image/gif");
ini_set("display_errors", "On");
$type=$_GET['type'];
$image=drawimage($link,$type);
imagegif($image);
//end of main
function drawimage($link,$type)
{
if($type==1)$image = imagecreatefromgif("map.gif");
if($type==2)$image = imagecreatefromgif("map2.gif");

return($image);
}

?>

Try using this and see if it works... If it does, it might be something in your SQL causing it.

hwttdz

3:26 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



I was getting some sort of error, but you can't see the errors in image header areas, probably a semicolon or bracket or something, so I just commented out all of the sql stuff in the previous one that I had working. Again it worked if the types were the same for both images but not if they were set different.

hakre

4:14 pm on Jun 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i know it is a hard one to debug, because you can not output as text. one thing you can do: setup php to write an error log. that way you can read out error messages without having them lost.

anyway, the only difference i can find is within these lines:
[tt]if($type==1)$image = imagecreatefromgif("map.gif");
if($type==2)$image = imagecreatefromgif("map2.gif");[/tt]

i guess that map2.gif does not exists. it's only a guess but i think the error can be found here or the image is to small to be drawn on etc. pp. my shoot is the difference between these to .gif files.

--hakre

Sathallrin

4:20 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



When I tried it with the example I gave above, it worked with both image types (1 and 2). The only difference I can see from what I was using and you were using is the actual gif images. It worked fine with 2 images that I used.

hwttdz

5:01 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



Both imgtest3.php?type=1 and imgtest3.php?type=2 work but not if I try to call them from the same php file. Both map files exist, they're actually a copy of the same file because I thought maybe for some reason it couldn't use the same file for two different things.

Right now the code of imgtest3.php is

<?php
//start of main
header("Content-type: image/gif");
ini_set("display_errors", "On");
$type=$_GET['type'];
$image=drawimage(1,$type);
imagegif($image);
//end of main
function drawimage($link,$type)
{
$image = imagecreatefromgif("map.gif");
return($image);
}
?>

hwttdz

5:35 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



I have removed more code trying to simplify and narrow down the problem.

The page that I'm trying to view is:


<IMG SRC="ita.php?type=1">
<IMG SRC="ita.php?type=2">

and ita.php is


<?php
header("Content-type: image/gif");
$image=imagecreatefromgif("map.gif");
imagegif($image);
?>

This works if whatever comes after IMG SRC=" is exactly the same in each case, but if I pass a get parameter it crashes, and if I save one copy of ita as ita2 it crashes. But if I set one to map.gif and the other to map2.gif it works.

Sathallrin

6:17 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



Sounds like it is something strange with your server. I tried the exact code you posted in the last message and it worked perfectly fine.

hwttdz

6:33 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



Are you using a local server. I'm using the devside suite.

hakre

6:33 pm on Jun 17, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



okay: some servers have got limitation about CGI, memory and processes. please tell wether PHP is running as CGI (a cgi limit might exceed here in that case) or as apache module.

also, dig up memory php is allowed to use etc (check phpinfo();), maybe we can dig something up here of your problem.

hwttdz

6:53 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



Sorry I don't really know where to look, I've got phpinfo pulled up. Can you tell me how to tell if it's a CGI?

Sathallrin

7:06 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



I tested mine under my server running PHP Version 4.3.10 with Server API: CGI

It would be listed under "Server API" in phpinfo().

hwttdz

7:16 pm on Jun 17, 2005 (gmt 0)

10+ Year Member



Server API : Apache 2.0 Handler