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

outputing image directly to browser

can one "stream" image data to a browser?

I created an image using gd and when I do imagepng I just get the binary
data for the image written as text instead of the image itself. Now I'm
writing the file to a temp file and using html to load the temp but seems
like a waste of cycles and space ;/

Anyway around this?

Thanks,
Jon
Jun 8 '07 #1
8 2127
Jon Slaughter wrote:
can one "stream" image data to a browser?
Yeah, you can encode the image in base64, but IMHO it's not worth it.
Anyway around this?
The classic way: do <img src='foo.php'>, where foo.php is the *only* script
that runs imagepng().

This means: do *not* run imagepng() in your main script.

--
----------------------------------
Iván Sánchez Ortega -ivansanchez-algarroba-escomposlinux-punto-org-

El sentido común es el menos común de los sentidos
Jun 8 '07 #2
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jon Slaughter wrote:
I created an image using gd and when I do imagepng I just get the binary
data for the image written as text instead of the image itself. Now I'm
writing the file to a temp file and using html to load the temp but seems
like a waste of cycles and space ;/
The data: URI scheme was created with this sort of functionality in
mind, but it is not supported by many browsers and not recommended.

What you should be doing is caching the generated image files and
referencing those using <img>. Not a waste of cycles at all!

- --
Edward Z. Yang GnuPG: 0x869C48DA
HTML Purifier <htmlpurifier.org Anti-XSS HTML Filter
[[ 3FA8 E9A9 7385 B691 A6FC B3CB A933 BE7D 869C 48DA ]]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFGaKvnqTO+fYacSNoRAsNiAJ9o/tgwCoDEd63XnDGqoCeaNcsA2gCdEHfa
zrRmQ3s2dXQY23YsXhJ2CQk=
=UYap
-----END PGP SIGNATURE-----
Jun 8 '07 #3
Jon Slaughter wrote:
can one "stream" image data to a browser?

I created an image using gd and when I do imagepng I just get the binary
data for the image written as text instead of the image itself. Now I'm
writing the file to a temp file and using html to load the temp but seems
like a waste of cycles and space ;/

Anyway around this?
Basically, exactly what Iván Sánchez Ortega said.

Remember that GD example source code I gave you a few days ago? All you
have to do is put it in a file, for example "image.php."

Then in another file, perhaps an HTML document, use:

<img src="image.php" width="100" height="100" />

Assuming your actual image output is 100x100.

In this same fashion, if you pass parameters to the image.php script to
say output specific characters you can do:

imagestring($img, 10, 5, 5, $_POST['msg'], $fg);

Instead of:
$msg = " Your IP is {$_SERVER['REMOTE_ADDR']}";
imagestring($img, 10, 5, 5, $msg, $fg);
<img src="im*******************************@REMOVEHotma il.com"
alt="E-mail John Slaughter" width="100" height="100" />

<img src="im**************************@hotmail.com" alt="My Alternate
E-mail" width="100" height="20" />

Of course, remove the REMOVEs. I just put that there in case of harvesting.

(Yes, yes, I realize they could harvest it anyway, since you do not
disguise it. I was just trying to be nice. : ))

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 8 '07 #4

"-Lost" <ma****************@techie.comwrote in message
news:U8******************************@comcast.com. ..
Jon Slaughter wrote:
>can one "stream" image data to a browser?

I created an image using gd and when I do imagepng I just get the binary
data for the image written as text instead of the image itself. Now I'm
writing the file to a temp file and using html to load the temp but seems
like a waste of cycles and space ;/

Anyway around this?

Basically, exactly what Iván Sánchez Ortega said.

Remember that GD example source code I gave you a few days ago? All you
have to do is put it in a file, for example "image.php."

Then in another file, perhaps an HTML document, use:

<img src="image.php" width="100" height="100" />

Assuming your actual image output is 100x100.

In this same fashion, if you pass parameters to the image.php script to
say output specific characters you can do:

imagestring($img, 10, 5, 5, $_POST['msg'], $fg);

Instead of:
$msg = " Your IP is {$_SERVER['REMOTE_ADDR']}";
imagestring($img, 10, 5, 5, $msg, $fg);
<img src="im*******************************@REMOVEHotma il.com" alt="E-mail
John Slaughter" width="100" height="100" />

<img src="im**************************@hotmail.com" alt="My Alternate
E-mail" width="100" height="20" />

Of course, remove the REMOVEs. I just put that there in case of
harvesting.

(Yes, yes, I realize they could harvest it anyway, since you do not
disguise it. I was just trying to be nice. : ))
Thanks. I didn't realize you could do that. I guess it makes sense now that
I think about it ;)

Jon
Jun 8 '07 #5

"-Lost" <ma****************@techie.comwrote in message
news:U8******************************@comcast.com. ..
Jon Slaughter wrote:
>can one "stream" image data to a browser?

I created an image using gd and when I do imagepng I just get the binary
data for the image written as text instead of the image itself. Now I'm
writing the file to a temp file and using html to load the temp but seems
like a waste of cycles and space ;/

Anyway around this?

Basically, exactly what Iván Sánchez Ortega said.

Remember that GD example source code I gave you a few days ago? All you
have to do is put it in a file, for example "image.php."

Then in another file, perhaps an HTML document, use:

<img src="image.php" width="100" height="100" />

Assuming your actual image output is 100x100.

In this same fashion, if you pass parameters to the image.php script to
say output specific characters you can do:

imagestring($img, 10, 5, 5, $_POST['msg'], $fg);

Instead of:
$msg = " Your IP is {$_SERVER['REMOTE_ADDR']}";
imagestring($img, 10, 5, 5, $msg, $fg);
<img src="im*******************************@REMOVEHotma il.com" alt="E-mail
John Slaughter" width="100" height="100" />

<img src="im**************************@hotmail.com" alt="My Alternate
E-mail" width="100" height="20" />

Of course, remove the REMOVEs. I just put that there in case of
harvesting.

(Yes, yes, I realize they could harvest it anyway, since you do not
disguise it. I was just trying to be nice. : ))
Strange... my image is true color and I get an error about the image having
an error when its true color but works when I use imagecreate as in your
example or the one in the php manual... ;/ Do I have the wrong mime type or
is can I not use this method with true color? (was saving to a png file and
then loading that with <imgand it worked fine)

Thanks,
Jon
Jun 8 '07 #6
At Fri, 08 Jun 2007 02:44:02 +0200, Iván Sánchez Ortega let h(is|er)
monkeys type:
Jon Slaughter wrote:
>can one "stream" image data to a browser?

Yeah, you can encode the image in base64, but IMHO it's not worth it.
>Anyway around this?

The classic way: do <img src='foo.php'>, where foo.php is the *only* script
that runs imagepng().

This means: do *not* run imagepng() in your main script.
Ivan, can you explain why the main script shouldn't run it? I think I am
missing a clue here. Other than that I can only second your opinion on
streaming image data. Can't think of ANY useful application. But maybe
someone can?

--
Schraalhans Keukenmeester - sc*********@the.Spamtrapexample.nl
[Remove the lowercase part of Spamtrap to send me a message]

"strcmp('apples','oranges') < 0"

Jun 8 '07 #7
The problem has to do with require ;/ I put all the image captcha stuff in a
class and if I copy and paste that class into the file it works but if I use
require_once it doesn't ;/ (but it is able to load find the file AFAIK cause
when I debug it's able to step through it)... maybe not though. Can't see
why that would cause a problem ;/

Jon
Jun 8 '07 #8
i had the same problem that i would only see the weird text when i
tried outputing an image
check this :)
http://bjorntoday.com/pico.php?ID=20
this outputs a string as an images i can use the <imgtag no problem
because of header()

<?
header('Content-type: image/jpg'); //watch out that you have no white
spaces before <? or header throws a fit
$IMG= //your image string
print $IMG;

?>

i got my pictures saved in a database as blob so this is very
practical, yet i had the problem that the pictures where not caching,
so i got a lil help from the php manual, this works
<?

// Checking if the client is validating his cache and if it is
current.
if (isset($headers['If-Modified-Since']) &&
(strtotime($headers['If-Modified-Since']) == $TIME)) {// Client's
cache IS current, so we just respond '304 Not Modified'.
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $TIME).'
GMT', true, 304);
} else {// Image not cached or cache outdated, we respond '200 OK'
and output the image.
header('Last-Modified: '.gmdate('D, d M Y H:i:s', $TIME).'
GMT', true, 200);
header('Content-type: image/jpg');
print $IMG;
}
?>

$TIME in my case is stored in the database as well.

Jun 8 '07 #9

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

Similar topics

4
by: Martin | last post by:
This is probably more of an HTML question than PHP. Perhaps someone here can answer or point me to a proper newsgroup. How can I force the browser to reload an image from the server? I have a...
1
by: david | last post by:
I have a question, when I store images on my server, I can let user access them by url like http://myurl/images/(imagename). I want to have more control on it, I can provide user a url like...
11
by: tma | last post by:
I have the following HTML in use on my web page. I need it to show a graphic image on the page but do not know what to use in the codebehind to make the graphic appear. If I load the source url in...
17
by: santel_helvis | last post by:
Hi All, Could anyone tell me how to rotate the image in javascript. Which concepts I should concentrate to rotate the image
3
by: premier | last post by:
I have a web page that's taking in data from text boxes, drawing a chart to represent the data, and then outputting the chart in PNG format. What I cant figure out how to do, is to output the...
18
by: Auto | last post by:
Hello, I would like to know how do display an image into a Gridview (ASP.NET 2.0) taken directly from a DataBase, NOT using an URL, like described in this article: ...
6
by: PenguinPig | last post by:
Dear All Experts I would like to know how to convert a HTML into Image using C#. Or allow me contains HTML code (parsed) in Image? I also tried this way but it just display the character "<" &...
8
by: Alexander Fischer | last post by:
Hello, I am writing a gallery script and use imagecreatefromjpeg and fpassthru to output images without any change to them (i.e., no thumbnail creation etc. - just deliver the image via the php...
12
by: Mads Aggerholm | last post by:
Hello Sirs I hope you can give me a hint to this little problem. The thing is, I have for a lang time enjoyed the comics on www.washintonpost.com, and I allways start the day by going to their...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.