0

I was reading this blog http://alexrogan.com the writer talks about adding an encoded image to a web page. His explanation was easy enough to understand, however he did not explain how to encode the image in the first place.

So, I would like to know how do I encoding an image?

Thanks

Bill
  • 291
  • 3
  • 5
  • 14
  • 2
    What does this question have to do with its soup of tags? The short answer: [use a base64 encoder](http://stackoverflow.com/search?q=base64+encoder). Could you pick a specific language? – Matt Ball May 19 '11 at 21:48
  • 1
    It is indeed language specific – Oskar Kjellin May 19 '11 at 21:49
  • http://www.greywyvern.com/code/php/binary2base64 will create base64 representation of your image, given a URL. After that, throw some html around it, and you're done. – Swati May 19 '11 at 21:51
  • If you want to embed images in CSS, I've created a tool (shameless plug) to do it automatically: http://code.google.com/p/css-image-embedder/ – Chris Laplante May 19 '11 at 21:53
  • I was not sure if it was language specific, so I did not know what language to tag – Bill May 19 '11 at 21:55

2 Answers2

4

Here's a php sample:

<?php

$data = file_get_contents('somepic.jpg');
$base64 = base64_encode($data);

?>

<img src="data:image/jpeg;base64,<?php echo $base64 ?>" />

base64 is base64, no matter what OS you're on.

Marc B
  • 356,200
  • 43
  • 426
  • 500
0

You need a base64 encoder for that. Try for example http://www.motobit.com/util/base64-decoder-encoder.asp. Upload your image to the site and a base64 representation will be generated for you to cut-and-paste into your HTML.

Kris
  • 2,108
  • 18
  • 19