Question

Embed Image in HTML

Asked by: poohbear_68

For efficiency reasons, as well as for purposes of server-side statelessness, I would like to embed the image data of a gif directly in my HTML.  This is described in http://www.elf.org/essay/inline-image.html, however, none of the examples work in Internet Explorer.

There's no problem using JavaScript--it's just that I was unable to find any example that worked.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-05-10 at 20:52:28ID21419932
Tags

embed

,

html

,

image

Topic

Hypertext Markup Language (HTML)

Participating Experts
4
Points
125
Comments
10

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Animated GIFs vs JavaScript image swapping
    What are the main differences between Animated GIFs and JavaScript image swapping for the delivery of simple images on the net? also which is best?
  2. Embed image in e-mail
    I want to embed an image in an e-mail I suppose i must attach this image to the message and then use a cid url to embed the image in html code like the following: <img src"cid:MY_CID_URL"> but I don't know how togenerate the cid url has anybody an idea ? thank...
  3. Embed an image in an HTML file
    Hello there I would like to embed an image in an HTML file. Not attached as a link, but actually bundled as part of the same file. I think mail messages use this. You receive HTML mail with pictures, but no attached files. Presumably there is some sort of text format that ...
  4. Embed an image in an object tag?
    I want to embed an image within an HTML file, kind of like MHT does. What hopefully I can do is this... put the actual raw image data into perhaps an object or embed tag and display that instead of an img tag. Something like... <object type="image/gif" height=...
  5. Displaying 2 Javascript Delivered Images Inline
    I have a <div> Inside it displays the results of 2 javascripts <script language="JavaScript" type="text/javascript">image1</script> <script language="JavaScript" type="text/javascript">image2</script> I'...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ZylochPosted on 2005-05-10 at 22:55:16ID: 13975292

One of the methods they speak of on the site is directly putting the image data in the image tag. This works for all browsers besides I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EyxsEyxsEyxsDuqqSqjoiqjoiqjoiqjoiqj oiqjoiqjoiqjoiqjoiqjogAqo6I7qqlMsbBMsbBMsbBMsbBMsbBMsbBMsbBMsbBMsbA7qqkqo6Iq o6Iqo6Iqo6Iqo6Iqo6Iqo6Iqo6Iqo6IAKqOiKqOiO6qpTLGwTLGwTLGwTLGwTLGwTLGwTLGwTLGw TLGwO6qpKqOiKqOiKqOiKqOiKqOiKqOiKqOiKqOiACqjoiqjoiqjojuqqUyxsEyxsEyxsEyxsEyx sEyxsEyxsEyxsEyxsDuqqSqjoiqjoiqjoiqjoiqjoiqjoiqjogAqo6Iqo6Iqo6Iqo6I7qqlMsbBM sbBMsbBMsbBMsbBMsbBMsbBMsbBMsbA7qqkqo6Iqo6Iqo6Iqo6Iqo6Iqo6IAKqOiKqOiKqOiKqOi KqOiO6qpTLGwTLGwTLGwTLGwTLGwTLGwTLGwTLGwTLGwO6qpKqOiKqOiKqOiKqOiKqOiACqjoiqj oiqjoiqjoiqjoiqjojuqqUyxsEyxsEyxsEyxsEyxsEyxsEyxsEyxsEyxsDuqqSqjoiqjoiqjoiqj ogAqo6Iqo6Iqo6Iqo6Iqo6Iqo6Iqo6I7qqlMsbBMsbBMsbBMsbBMsbBMsbBMsbBMsbBMsbA7qqkq o6Iqo6Iqo6IAKqOiKqOiKqOiKqOiKqOiKqOiKqOiKqOiO6qpTLGwTLGwTLGwTLGwTLGwTLGwTLGw TLGwTLGwO6qpKqOiKqOiACqjoiqjoiqjoiqjoiqjoiqjoiqjoiqjoiqjojuqqUyxsEyxsEyxsEyx sEyxsEyxsEyxsEyxsEyxsDuqqSqjogAqo6Iqo6Iqo6Iqo6Iqo6Iqo6Iqo6Iqo6Iqo6Iqo6I7qqlM sbBMsbBMsbBMsbBMsbBMsbBMsbBMsbBMsbA7qqkA" />

You may change image/png to image/jpg or image/gif but IE still refuses to show the image. You can find the encoding of the image by using this PHP code:

<?php
$fp = fopen("pic.jpg","rb");
$picture = fread($fp,filesize("pic.jpg"));
fclose($fp);
$base64 = chunk_split(base64_encode($picture));
echo "<img src=\"data:image/png;base64,".$encoded."\" />';
?>

I will test the other methods in IE for you.

 

by: ZylochPosted on 2005-05-10 at 23:00:31ID: 13975306

The first Javascript method did not seem to work in either Firefox or IE, or I might just be implementing it wrong. Anyhow, I would not suggest using such a method currently. The browsers are not well designed to handle these changes yet. Who knows? Perhaps in the next release of Firefox or in IE7, things will be in a better light!

 

by: poohbear_68Posted on 2005-05-11 at 05:07:55ID: 13976939

The first method is definitely a clean solution, but it's not worth implementing anything if I there's no solution that works in Internet Explorer.  I may have to resign to waiting for IE 7.

I presume that binding an image will only set its url, not the actual data?

 

by: gregoryyoungPosted on 2005-05-13 at 16:18:38ID: 14000496

umm it is a clean solution (of course it uses 3 times the bandwith on the base64 encoding).

check here ... works in most major browsers.

http://www.bennherrera.com/EmbeddedImage/

Greg

 

by: GrandSchtroumpfPosted on 2005-05-13 at 16:42:53ID: 14000584

> http://www.bennherrera.com/EmbeddedImage/
Geez louise... Those are TABLES!!!
That's quite interesting.

 

by: gregoryyoungPosted on 2005-05-13 at 17:52:47ID: 14000783

that they are ... a rather simple implmentation but it works (and in i.e.) :)

anyway you do it, its a bad idea for anything more than 64x64 MAYBE 128x128 as it absolutly kills your throughput.

Greg

 

by: poohbear_68Posted on 2005-05-13 at 19:04:32ID: 14000939

This idea is indeed a highly creative one and effectively deals with the browser limitations in Internet Explorer--the first solution I've encountered that even begins to work in IE.  The problem of throughput is a cost that is inherent with embedding binary data in a text transport.

The biggest problem with this solution is that, from the standpoint of a user, it does not feel like an authentic solution.  Here's why:

-A printable 256x256 image takes anywhere from 200ms-750ms to render.  Internet Explorer hangs during this time, and makes the site seem slow.
-The user cannot right-click on the image to save a copy.
-Copying out the image to the clipboard and pasting it into an application such as Microsoft Word is very slow, and of course, Microsoft Word does not come close to rendering this as an image.

These problems could perhaps be overcome by:

-Optimizing the image rendering.  I am unsure how document.write calls into an IFRAME compares with DOM generation.  If I recall correctly, the latter is somewhat slow in most browsers, especially when used extensively.  I'm curious how document.write would perform when rendering an image with particularly succinct HTML.
-The right-click could be disabled, and a link could be added to the page that would allow the user to download the image through a separate request to the server.  (The purpose of this embedded image, as I pointed out earlier, is to lessen the burden of statefulness by the server.  The user would need to wait 20-30 seconds for the server to generate the image when saving to the hard-drive.)
-The document could be laid out in such a way that, with some JavaScript coding, the user would be unable to select the image.  (Obviously this would have to happen at a lower level than mere mouse clicks.)

Then, I would end up with a generic DHTML/JavaScript control that would look and feel very much like a flash control.

In summary, this is a very interesting idea and may merit points not because it is a solution that performs particularly well, but because it is a solution that performs at all.

 

by: poohbear_68Posted on 2005-05-13 at 19:20:32ID: 14000964

Having written an essay about the table approach, I would like to offer two counter solutions that I thought of, not because I believe they're the ideal solution, but because I believe a critique must follow up with constructive feedback.

My first idea is quite simple: the server could have a custom script that would receive the contents of the image in the query string (if IE indeed allows URLs that long; otherwise, in the POST data), and return it as an image.  Yes, this does mean that the image content is transferred three times--twice in a text-friendly format (perhaps base36 encoded or some other proprietary format) and once in a binary format.

My second idea is similar, although I'm not exactly sure of the implementation details.  Essentially, the src of the image could contain the base64-encoded version of the image, and the low-res url could contain a path to the lengthy server-side process that regenerates the image.  Presumably IE would not recognize the first and would request the image from the second URL.  All other browsers would render the image immediately.

Here's yet a twist on these ideas:  The HTML page containing the image could include a global JavaScript variable including the base64 encoded data.  In IE, the script would write out an image with a url for either the give-me-an-image-for-this-data script (idea 1) or the lengthy server-side process (idea 2).  For all other browsers, it would simple write out an image tag with the base64 encoded data in the src tag.

The problem with these ideas is that it penalizes users for browsing with IE.  This is a controversial subject, of course, but given the large target audience of IE users, I believe it's a fairly large strike against the ideas.

If the problem cannot be satisfactorily solved client-side (which I hate to say is true, but might be), the only option is beefing up the servers.  I cannot pre-emptively generate my HTML page, because the server process needs to display a status.  The obvious server-side solution is optimizing the server application until the image can be generated through its own URL/entrypoint.  At that point, the HTML page can be generated either pre-emptively or using the same backend server process.  Perhaps that's what everyone else has been doing up till now.  Still, that's a lot of work, and I believe there would be a good bit of potential in well-designed embedded images.

 

by: poohbear_68Posted on 2005-05-17 at 08:05:51ID: 14019312

As a final thought (as I mentioned before) the accepted solution ay not merit points not because it is a solution that performs particularly well, but because it is a solution that performs at all.  The best solution is to wait for the IE7 beta and explore the possibilities there.

 

by: tweensteeplesPosted on 2009-11-08 at 17:19:31ID: 25772885

that is a completely stupid idea. you guys need to do some research and get this question answered. stop linking to off-site crap. cut and paste if you have to but stop taking me off-site to dead links. lazy, lazy, lazy, lazy.

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...