davidrickard.net

Random stuff, randomly updated.

Archive for December, 2006

Getting all your images inline

Wednesday, December 20th, 2006

Ignore the punny title.

Quite a few times I’ve needed to use an image in an HTML page, but I’ve been unable to just link to it like you normally would. This has happened with systems like captive portals, or filtering proxies where an error page needs a logo or something. Usually the only option is to link to another web server, which I don’t like to do. I prefer things nicely self-contained.

So I found this document recently, which outlines quite how to do it. I knocked together a little PHP script which will convert a .JPG or .GIF file to a base64 string, and present you with a nice URL to embed. Simple! Apparently this method has been kicking about since 1998. I’ve looked for a method countless times and never found it!

Anyway, the PHP script is here, so you can try it too! It ran fine on my Mac (OS 10.4, Apache 2 and PHP5 IIRC!). I suppose it should run on any PHP server.

Edit to add, I’ve been informed it doesn’t work in Internet Explorer. Then again, what does?