HOWTO: output a picture in the middle of a page

This is a discussion on HOWTO: output a picture in the middle of a page within the PHP Language forums, part of the PHP Programming Forums category; I want to generate a web page using PHP, and in the middle generate a graphic I read from another ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 06-04-2004
Tim Streater
 
Posts: n/a
Default 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.
Reply With Quote
  #2 (permalink)  
Old 06-04-2004
kingofkolt
 
Posts: n/a
Default Re: HOWTO: output a picture in the middle of a page

"Tim Streater" <tim.streater@dante.org.uk> wrote in message
news:tim.streater-C7DF5E.17582804062004@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">';
}
?>


Reply With Quote
  #3 (permalink)  
Old 06-04-2004
kingofkolt
 
Posts: n/a
Default Re: HOWTO: output a picture in the middle of a page

"kingofkolt" <jessepNOSPAM@comcast.net> wrote in message
news:952wc.50566$Ly.48896@attbi_s01...
> "Tim Streater" <tim.streater@dante.org.uk> wrote in message
> news:tim.streater-C7DF5E.17582804062004@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 '='


Reply With Quote
  #4 (permalink)  
Old 06-08-2004
Jin Mazumdar
 
Posts: n/a
Default Re: HOWTO: output a picture in the middle of a page

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" <jessepNOSPAM@comcast.net> wrote in message
> news:952wc.50566$Ly.48896@attbi_s01...
>
>>"Tim Streater" <tim.streater@dante.org.uk> wrote in message
>>news:tim.streater-C7DF5E.17582804062004@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 '='
>
>


Reply With Quote
  #5 (permalink)  
Old 06-09-2004
Dennis Biletsky
 
Posts: n/a
Default Re: HOWTO: output a picture in the middle of a page

> 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']);
?>


Reply With Quote
  #6 (permalink)  
Old 06-09-2004
Jin Mazumdar
 
Posts: n/a
Default Re: HOWTO: output a picture in the middle of a page


> 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.

Reply With Quote
  #7 (permalink)  
Old 06-10-2004
Tim Streater
 
Posts: n/a
Default Re: HOWTO: output a picture in the middle of a page

In article <E4adnTb887G7g1rdRVn-jw@comcast.com>,
Jin Mazumdar <mazumdar_REMOVE_@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
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 08:33 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0