April 12, 2005

Embedding Images

Did you know you could embed any mime data in an HTML page? I didn't. What does this mean?

It means you can place an image inline in a page.

data:<mimetype>;base64,<data> is how you code it. The example here is a base64 PNG, taken straight from rifers.org.

RIFE Logo

Which is cool, but has high potential for evil. Which makes me think that it will be (or already is) be used in that way. Which means that it will probably (or should) disappear from browsers.

But it is a neat thing I never knew about. It does only work in Firefox, Safari, Opera. Not IE. (via)

Post Info

Tagged As HTML

Comments are Open (3)

Posted at 08:11 AM

Comments

Richard@Home

Now that IS cool, especially if you want to produce stand alone documents (reports with graphs and no dependencies for instance).

What tool did you use to produce the

img src="data:image/png;base64,iVBORw0KGgoAAAANSUh...

string?

Tony

I cheated. I just copied the source of the image from their site.

I've done some quick experimenting in trying to getting the code of the image. If you try and open an image file into a text editor it doesn't work in this instance. The source needs to be base64. That's the important step.

dysfunksional.monkey

Quick way of getting the information using PHP:
<?php
$image = $_GET['imgsrc'];
list(, , , $attr, $mime) = getimagesize($image);
echo '&lt;img src="data:'.$mime.';base64,'.base64_encode(file_get_contents($image)).'" '.$attr.' /&gt;';
?>
This will produce the image tag directly on the page for you to copy and paste.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)

Search
Comments on this post
Categories
Info
Tony Stephens
Copyright © 1995-2005
Site Version:
10
Licensed:
Creative Commons
Validate:
XHTML, CSS, 508, RSS
Subscribe
Blog-Fu, Link-Fu