The Archives

SEARCH

About There4

I build simple, clean, and maintainable internet applications. People should never need an owners manual to use software, I believe that applications can be easy to use while still being powerful. Applications should remain valuable through their entire lifespans, and should be flexible enough to grow and change as requirements shift.

I prefer to develop with Blueprint CSS, jQuery, and Cake PHP. I have extensive development history with PHP, MySQL, Microsoft SQL, and mixed Win32/Linux hosting environments.

Follow me on Twitter

Posting tweet...

Archive for February, 2009

Smarty template function for the data uri format

Posted in: Blog, PHP by Craig Davis on February 12, 2009

In a recent project, I needed to provide an html document that could be used offline. After initially experimenting with zip files and other methods of delivering the associated image files, I chose to use the somewhat rare method of using the data uri scheme. This provides us with the ability to place the image data in-line with the page.

Download the modifier

The approach is straightforward. We must base64 encode the image data and place it with the proper formatting into the src attribute of an img tag. The processing is accomplished in this case with a smarty modifier.

<img src="{img2data path='/images/inline.gif'}" />