473,659 Members | 2,886 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2141
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.o rg 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 +fYacSNoRAsNiAJ 9o/tgwCoDEd63XnDGq oCeaNcsA2gCdEHf a
zrRmQ3s2dXQY23Y sXhJ2CQk=
=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($im g, 10, 5, 5, $_POST['msg'], $fg);

Instead of:
$msg = " Your IP is {$_SERVER['REMOTE_ADDR']}";
imagestring($im g, 10, 5, 5, $msg, $fg);
<img src="im******** *************** ********@REMOVE Hotmail.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.com wrote 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($im g, 10, 5, 5, $_POST['msg'], $fg);

Instead of:
$msg = " Your IP is {$_SERVER['REMOTE_ADDR']}";
imagestring($im g, 10, 5, 5, $msg, $fg);
<img src="im******** *************** ********@REMOVE Hotmail.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.com wrote 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($im g, 10, 5, 5, $_POST['msg'], $fg);

Instead of:
$msg = " Your IP is {$_SERVER['REMOTE_ADDR']}";
imagestring($im g, 10, 5, 5, $msg, $fg);
<img src="im******** *************** ********@REMOVE Hotmail.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 .Spamtrapexampl e.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($hea ders['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
42775
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 page where the user can set some parameters and click a <submit> button. A PHP script then generates a .png graphic and saves it to disc. An html statement (<p><img src="gMyGraphic.png"></p>) then sends the graphic out to the browser.
1
1231
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 http://myurl/file/(imagename). Then in the dll that handle the url, I can use httpresponse.writefile. I am wonderring how much burden it will bring on a server? is it a good idea to do that way? Thanks!
11
2870
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 a browser by itself, the graphic appears, but when I use the tag in a web page it does not. Anyone have a suggestion for VB? <img src='http://www.domain.com/MohawkWS/MohawkHitCounter.aspx?ItemID=7103830413' border=0 alt>
17
29395
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
1578
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 chart as part of an aspx web page. Ideally, I'd output it to the bottom of the web page that the user used to send the data to the server. Or, I could output the PNG as part of a new Web page. I'm just lost on the details. I'm currently...
18
6501
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: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnaspp/html/GridViewEx06.asp I have NO URL, i have the binary image inside the DB, like the field "Photo" in the table "Employees" of the "NWIND.MDB" DataBase.
6
29439
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 "<" & ">" directly.... I have done googling, but all return shareware. I would like to know how to programming...but not using shareware... Thanks all.
8
3032
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 script). However I note that the image creation is quite slow - the user can see that the image is created line-by-line, from top to bottom. Most likely this speed issue comes from PHP, since PHP is simply slower than C etc.
12
2901
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 homepage. One day, I thought: Why not just make a little program in C#, that just shows me the .gif-picture of the strip? And so I did. Or, more correctly, I tried to do.
0
8427
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8332
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8746
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7356
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6179
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5649
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4335
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2750
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1975
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.