473,382 Members | 1,252 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,382 software developers and data experts.

HOWTO: output a picture in the middle of a page

I want to generate a web page using PHP, and in the middle generate a
graphic I read from another server. So the graphic is in $picture. So I
can either write $picture to a temp file and then use an ordinary <img
src=filename> to get the browser to display it, or output it by itself
in a new page, because then I have a chance to output the correct header
so I don't just get garbage on the screen.

Evidently first approach is poor because I have to write a local file,
and second approach is not what I want anyway.

Is there a way to do this? That is, I have $picture that contains an
image, and I want to output it here and now in this HTML page I am in
the middle of creating, and have it show as a picture.

Thanks for any pointers.
Jul 17 '05 #1
6 5197
"Tim Streater" <ti**********@dante.org.uk> wrote in message
news:ti********************************@individual .net...
I want to generate a web page using PHP, and in the middle generate a
graphic I read from another server. So the graphic is in $picture. So I
can either write $picture to a temp file and then use an ordinary <img
src=filename> to get the browser to display it, or output it by itself
in a new page, because then I have a chance to output the correct header
so I don't just get garbage on the screen.

Evidently first approach is poor because I have to write a local file,
and second approach is not what I want anyway.

Is there a way to do this? That is, I have $picture that contains an
image, and I want to output it here and now in this HTML page I am in
the middle of creating, and have it show as a picture.

Thanks for any pointers.


<?php // begin thispage.php
if ($_GET['action']="img") {
header("Content-type: image/jpeg");
// output image here
} else {
echo '<img src="thispage.php?action=img">';
}
?>
Jul 17 '05 #2
"kingofkolt" <je**********@comcast.net> wrote in message
news:952wc.50566$Ly.48896@attbi_s01...
"Tim Streater" <ti**********@dante.org.uk> wrote in message
news:ti********************************@individual .net...
I want to generate a web page using PHP, and in the middle generate a
graphic I read from another server. So the graphic is in $picture. So I
can either write $picture to a temp file and then use an ordinary <img
src=filename> to get the browser to display it, or output it by itself
in a new page, because then I have a chance to output the correct header
so I don't just get garbage on the screen.

Evidently first approach is poor because I have to write a local file,
and second approach is not what I want anyway.

Is there a way to do this? That is, I have $picture that contains an
image, and I want to output it here and now in this HTML page I am in
the middle of creating, and have it show as a picture.

Thanks for any pointers.


<?php // begin thispage.php
if ($_GET['action']="img") {
header("Content-type: image/jpeg");
// output image here
} else {
echo '<img src="thispage.php?action=img">';
}
?>


CORRECTION:

change line 2 to:

if ($_GET['action']=="image") { // I forgot the second '='
Jul 17 '05 #3
Won't this complain that the header has already been sent assuming that
thispage.php is sending HTML before the image? I have been trying to
find a solution around this too.

kingofkolt wrote:
"kingofkolt" <je**********@comcast.net> wrote in message
news:952wc.50566$Ly.48896@attbi_s01...
"Tim Streater" <ti**********@dante.org.uk> wrote in message
news:ti********************************@individu al.net...
I want to generate a web page using PHP, and in the middle generate a
graphic I read from another server. So the graphic is in $picture. So I
can either write $picture to a temp file and then use an ordinary <img
src=filename> to get the browser to display it, or output it by itself
in a new page, because then I have a chance to output the correct header
so I don't just get garbage on the screen.

Evidently first approach is poor because I have to write a local file,
and second approach is not what I want anyway.

Is there a way to do this? That is, I have $picture that contains an
image, and I want to output it here and now in this HTML page I am in
the middle of creating, and have it show as a picture.

Thanks for any pointers.


<?php // begin thispage.php
if ($_GET['action']="img") {
header("Content-type: image/jpeg");
// output image here
} else {
echo '<img src="thispage.php?action=img">';
}
?>


CORRECTION:

change line 2 to:

if ($_GET['action']=="image") { // I forgot the second '='


Jul 17 '05 #4
> Won't this complain that the header has already been sent assuming that
thispage.php is sending HTML before the image? I have been trying to
find a solution around this too.


[snip]

Thanks for any pointers.

<?php // begin thispage.php
if ($_GET['action']="img") {
header("Content-type: image/jpeg");
// output image here
} else {
echo '<img src="thispage.php?action=img">';
}
?>


CORRECTION:

change line 2 to:

if ($_GET['action']=="image") { // I forgot the second '='

Try to use separate script for image output like this:
image.html
<html><head><title>Image output</title></head><body><img
src=image.php?imagename=imagename></body></html>

image.php
<?
header("Content-type: image/gif");
readfile($_GET['imagename']);
?>
Jul 17 '05 #5
Try to use separate script for image output like this:
image.html
<html><head><title>Image output</title></head><body><img
src=image.php?imagename=imagename></body></html>

image.php
<?
header("Content-type: image/gif");
readfile($_GET['imagename']);
?>


Yes, that is one way of doing it and is what I am doing now. However,
there are limitations to it.

First, myphpfile is a separate script and one has to pass the bits in
$picture into it which is inefficient and perhaps not much better than
creating a file.

The second more serious drawback is when you want to display multiple
pictures. The following will not work and will display the second
picture twice.

<img src="myphpfile.phtml">

$picture=<second picture>

<img src="myphpfile.phtml">

Of course you can get by with something like the following after
modifying the myphpfile script

<img src="myphpfile.phtml">

$picture2=<second picture>

<img src="myphpfile.phtml?num=2">

but this makes everything even more inefficient as you now have to pass
more data from one script to another.

It would be neat to find a way to display the image directly from the
original script but I am not sure it can be done in php.

Jul 17 '05 #6
In article <E4********************@comcast.com>,
Jin Mazumdar <ma**************@REMOVE.comcast.net> wrote:
Try to use separate script for image output like this:
image.html
<html><head><title>Image output</title></head><body><img
src=image.php?imagename=imagename></body></html>

image.php
<?
header("Content-type: image/gif");
readfile($_GET['imagename']);
?>


Yes, that is one way of doing it and is what I am doing now. However,
there are limitations to it.

First, myphpfile is a separate script and one has to pass the bits in
$picture into it which is inefficient and perhaps not much better than
creating a file.

The second more serious drawback is when you want to display multiple
pictures. The following will not work and will display the second
picture twice.

<img src="myphpfile.phtml">

$picture=<second picture>

<img src="myphpfile.phtml">

Of course you can get by with something like the following after
modifying the myphpfile script

<img src="myphpfile.phtml">

$picture2=<second picture>

<img src="myphpfile.phtml?num=2">

but this makes everything even more inefficient as you now have to pass
more data from one script to another.

It would be neat to find a way to display the image directly from the
original script but I am not sure it can be done in php.


In the end I did something like this too. As I was obtaining the picture
in the second script, and just in effect passing a pointer to this
script so it knew which picture to get, there was no extra overhead
because that was work needing to be done anyway.

Thanks for all feedback.

--tim
Jul 17 '05 #7

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

Similar topics

8
by: Martin | last post by:
I am interested to know of other peoples 'best ways' to print calculation results to the screen and printer, using VB6. My usual out put is a single page up to four pages mostly text and figures...
4
by: DraguVaso | last post by:
Hi, In my application I receive a Byte Stream (Dim bytFile() As Byte) which contains a jpeg-picture, which I want to display in a picturebox. I want to display it directly from the bytfile()...
4
by: Michael T. Peterson | last post by:
I am unable to figure out how to overload the '==' operator. The code below( cc'd it from an example on the net) doesn't compile: bool operator== ( const GivenName &lhs, const GivenName &rhs ) {...
3
by: Kamyk | last post by:
Hello all! I would like to open a new window with a picture after clicking on a shrinked picture which is located on the main page. I want this new window to be exactly sized as original...
2
by: Casey Miller | last post by:
I have a site, http://www.onemorewebsite.com, that has a menu on the left side and a picture on the right side with a middle div for content in the middle. When I mouse over the menu, the picture...
8
by: mosscliffe | last post by:
I am an old programmer, but a newbie to Visual Web Developer 2005 - Express Edition I have an .aspx Form Page with an attached Master File and an attached css file. I have scanned a text...
2
by: ATS | last post by:
HOWTO Override ASP's Response output for 2003/IIS. Please help, I want to have an ASP page write back EVERYTHING to the ASP Response. That includes HTTP Headers. I want my ASP to look...
3
by: rsteph | last post by:
I have a script that shows the time and date. It's been working on my site for quite a while now. Suddenly it stops showing up, after getting my drop down menu to work. If I put text between the...
0
by: solostation | last post by:
Hi I need to modify the output size upon click on 'more photos" so that I can add some pictures in the out put box ... The relevent html code I can find (copied from the display html) is as...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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...

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.