schmmd
schmmd

Reputation: 19468

How to load a dynamic image into a web page?

I have a web page and I would like to display a graph. I want to be able to specify the graph dynamically using DOT language. So I made a page that takes a DOT expression for the query parameter and returns image content. Now I can simply add an img tag with the appropriate `src.

<img src="/dot/png/graph{a--b}">

However, some servers have trouble with the long URLs. Is it possible to get an image via a POST request and display it in the img tag with JavaScript?

Upvotes: 4

Views: 1211

Answers (1)

Peter Olson
Peter Olson

Reputation: 142921

The only thing I can think of is having the server return a base64 encoded string of the image data, which you could include in an img tag like this:

<img src="data:image/png;base64,BASE64STRINGGOESHERE">

Be warned that the data URI scheme is not supported in IE7 and below, and that IE8 only allows 32KB of data in a URI.

Upvotes: 1

Related Questions