How to embed images in a single HTML / PHP file?

Posted by Tatu Ulmanen on Stack Overflow See other posts from Stack Overflow or by Tatu Ulmanen
Published on 2010-02-24T20:44:54Z Indexed on 2010/03/09 10:21 UTC
Read the original article Hit count: 378

Filed under:
|
|
|
|

Hi,

I am creating a lightweight, single-file database administration tool and I would like to bundle some small icons with it. What is the best way to embed images in a HTML/PHP file?

I know a method using PHP where I would call the same file with a GET parameter that would output hardcoded binary data with the correct header, but that seems a bit complicated.

Can I use something to pass the image directly in a CSS background-image declaration? This would allow me to utilize the CSS sprite technique.

Browser support isn't an issue here, so more exotic methods are welcome also.

EDIT

Does someone have a link/example to how to generate Data URL's properly with PHP? I'd figure echo 'data:image/png;base64,'.base64_encode(file_get_contents('image.png')) would suffice but I could be wrong.

© Stack Overflow or respective owner

Related posts about image

Related posts about embed