473,382 Members | 1,302 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.

embedding images in HTML with the data URL src

I have been doing some research about embedding images in HTML using
the data URL src method of the format:

<img src="/-/data:image/gif;base64,<DATA>">

My question is, how does one generate this <DATA> string? I have found
some on the web that I can load into my browser but if I save this
image and then view in Notepad it looks much different than the string
that I used in <DATA> and is full of non-alphanumeric symbols. Also, I
have saved this image as a BLOB into my database and this format is in
turn different from the two other. What gives?

Thanks.

Edward

Jan 28 '06 #1
6 22770
Edward wrote:
I have been doing some research about embedding images in HTML using
the data URL src method of the format:
Have you studied the specification of data: URLs and the browser support
to them?
<img src="/-/data:image/gif;base64,<DATA>">
Apparently not. And your markup isn't even valid.

Besides, even if you got it right, and even if browsers generally
supported it (say, in 2009), would it still be _useful_ to use it?
My question is, how does one generate this <DATA> string?


It's too early to ask that, since you haven't addressed the more
fundamental issues. Besides, it's not an HTML issue.
Jan 28 '06 #2
Edward wrote:
I have been doing some research about embedding images in HTML using
the data URL src method of the format:

<img src="/-/data:image/gif;base64,<DATA>">

My question is, how does one generate this <DATA> string?


http://software.hixie.ch/utilities/cgi/data/data

--
Lachlan Hunt
http://lachy.id.au/
http://GetFirefox.com/ Rediscover the Web
http://GetThunderbird.com/ Reclaim your Inbox
Jan 28 '06 #3

Jukka K. Korpela wrote:
Edward wrote:
I have been doing some research about embedding images in HTML using
the data URL src method of the format:
Have you studied the specification of data: URLs and the browser support
to them?


I am trying to learn all I can about the data: URL. Clearly I am not
yet an expert! But I hope to learn from others in this forum and in my
other research. I am trying to progress.
<img src="/-/data:image/gif;base64,<DATA>">


Apparently not. And your markup isn't even valid.


How so? I have been able to open images in browsers using this markup.
I found some good examples at:
http://delegate.org/delegate/sample/data-url.html.
Besides, even if you got it right, and even if browsers generally
supported it (say, in 2009), would it still be _useful_ to use it?


I hope so. I am not going to use it in the browser, per se, however.
I plan to use it to pass a parameter to Apache FOP to load an
external-graphic. I need to use a data: URL because the image
generation servlet is required to use HTTPS and FOP does not seem to
support HTTPS in an external-graphic.
My question is, how does one generate this <DATA> string?


It's too early to ask that, since you haven't addressed the more
fundamental issues. Besides, it's not an HTML issue.


I have found a web site to encode data to Base64
(http://makcoder.sourceforge.net/demo/base64.php) and a class that
someone wrote
(http://www.source-code.biz/snippets/...oder.java.txt). Using
both of these methods, I took the sample <DATA> from above (which
created the image in a browser) and then saved this image. I then used
the two methods here to try to recreate the <DATA>. The recreated
<DATA> was close but not the same as the original. I think that I must
be missing something obvious on how to create the Base64 data.

Jan 28 '06 #4
Edward <ed**************@yahoo.com> wrote:
How so? I have been able to open images in browsers using this markup.
I found some good examples at:
http://delegate.org/delegate/sample/data-url.html.


Forget this page immediately.

The second example of this page (with the "/-/" prepended to the data
url) will result in the following:
The relative URL "/-/data:image/gif;base64,<data>" will be resolved
to "http://delegate.org/-/data:image/gif;base64,<data>" and then will be
send back to the server. The server now translates the "<data>" into a
GIF image and sends this image back to the browser which it can display.
In the first example (the real "data:" URL scheme) will result in the
following:
The URL "data:image/gif;base64,<data>" will be directly translated into
a GIF image by the browser and so can be directly displayed.

The differences is:
The second example needs more than the double amout of data that is send
to and from the server. And it is working only with the help
of the server, and only if the server is able to translate such
URLs. That means there must be a certain script installed on your server
in order to use this special URLs. And because of the doubled data
transmission you'll better use the ordinary way to embed images

It doesn't make any sense to prepend "/-/" to "data:" URLs.

--
Alexander
Jan 28 '06 #5
Edward <ed**************@yahoo.com> wrote:
I have been doing some research about embedding images in HTML using
the data URL src method of the format:

<img src="/-/data:image/gif;base64,<DATA>">

^^^^
Remove this nonsense.

"data" URLs must begin with "data:" (like "http" URLs begin with
"http:"), because otherwise the whole thing is just an ordinary relative
URL which will be resolved using the base URL of the document itself.
That means instead of letting the browser deal with the "data" directly,
this will cause the browser to send the data back to the server. If the
server is not prepared for such a stupidity, you get only an error
message. If the server is able to translate the "data" of the "false"
data-URL into the real file format, it will send back the translated
data to the browser.

But of course. this is just a very stupid thing: you've more than
doubled the amount of data that is transmitted to and from the server.
And this won't work offline anymore, without a server that is
translating the data.

--
Alexander
Jan 28 '06 #6
"Edward" <ed**************@yahoo.com> wrote:
I am trying to learn all I can about the data: URL.
But you apparently did not even read the description of their format.
> <img src="/-/data:image/gif;base64,<DATA>">


Apparently not. And your markup isn't even valid.


How so? I have been able to open images in browsers using this markup.


Apparently you don't even know what "valid markup" means.
I need to use a data: URL because the image
generation servlet is required to use HTTPS and FOP does not seem to
support HTTPS in an external-graphic.


Whatever that's supposed to mean, it's not about HTML authoring for the WWW,
hence off-topic for this group.

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Pages about Web authoring: http://www.cs.tut.fi/~jkorpela/www.html

Jan 28 '06 #7

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

Similar topics

2
by: Dean J. Garrett | last post by:
Hi, I need to create HTML e-mail from an ASP program that includes embedded images that go along with the e-mail, e.g. logos, product image, etc. Is there a technique in HTML that people use to...
1
by: Chris Nafziger | last post by:
In my code to send email from VBScript, I use standard CDOSYS code similar to the following: With oMsg Set .Configuration = oCon .To = """Admin"" <admin@mycompany.com>" .From =...
2
by: dr_tyson | last post by:
I am trying to embed images into a wxPython app (created using Boa Constructor), but have not been able to do so. I know how to embed plots, but images seem to be a problem. I've tried using code...
3
by: Tim T | last post by:
Hi, I hope there is someone reading this that has the answer, Please Help! I have the need to send a html email via asp.net. its easy enough to send an html email and add attachments. My...
7
by: David Thielen | last post by:
Hi; Is there a way to embed images in the response rather than writing them to disk and having an <img ...> tag? And if so, how is it done and what browsers support it? -- thanks - dave
1
by: MissMarie | last post by:
I've been playing around with DIV tables in myspace to better learn how to rewrite my own code for my business site without having to pay someone to design it. I've tried embedding a slideshow into...
0
by: macap.usenet | last post by:
Hello, i am embedding System.Web.UI.WebResources in my C# Class via: I use this resource with: Page.Header.Controls.Add(new LiteralControl("<link href='"ExtJS.yui- ext.css"'...
5
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL...
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
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
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: 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
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?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.