In the previous article I touched on one of the problems we encountered while working on our mobile site, namely— automatic image adaptation for mobile devices. In this follow-up article I’d like to share a solution we’ve come up with to improve the user experience, with the hopes that others might find it useful.
Device Grouping
When designing for mobile we typically begin by grouping devices by screen size, and common properties using a device database such as DeviceAtlas or WURFL. This not only provides us with a common base for the initial cross-platform design, but also potential patterns for dealing with progressive enhancement on more capable devices.
This approach works quite well as it allows us to adapt template and theme designs for specific device groupings; which in the end, results in a better user experience. The problems begin however once you start adding actual content to your CMS.
Unlike templates and themes which often include logic to adapt to various platforms—actual HTML content is typically static. A blob of HTML in a database, often designed to work in one context. This is especially true if the content happens to include images, as currently there is no means within HTML to provide alternative images in a manner similar to that of style sheets using media types.
Adaptation and Content Filtering
As mentioned in the previous article, a fully automated approach to image adaptation doesn’t always provide the best user experience on mobile devices. It works by ensuring that the image data fits within the display, but does nothing to ensure that the image itself is in fact still meaningful or usable.

Being designers, what we really wanted was a means of providing human-designed, alternate images that could replace the default image for specific device groups; without having to add logic (php code) to our content.
Introducing a DeviceAtlas - Mobile Image Replacement Filter
After picking the brains of a few developer colleagues we set about to create a plug-in for WordPress that would filter and evaluate images within HTML based upon a few simple rules, and then react accordingly.
- Look for a replacement image based on defined settings, if the device display width as reported by DeviceAtlas is less than that of the default image size specified.
- If an existing replacement image isn’t found, attempt to create a new image based on the groupings defined in a settings.ini file.
- Once a replacement image has either been found or created, replace the src, width and height attribute of the img tag within the html.
As a designer/developer, the above leaves you with two options.
- Include one image (of the default size), then let the plugin generate and replace the alternates for you. Or…
- Create a separate image for one, two, or even all of the sizes defined; then let the plugin replace them as needed.
In other words, should you need or want it; you have full editorial control over every size of every image.

The plugin has also been designed in order to load the DeviceAtlas API and data once upon a request and make both available within WordPress itself. This is useful as it enables easy device specific adaptations to templates and style sheets within the theme. In theory the API should even be available to other plugins.
Known Issues and Limitations
First off — we’re designers, not developers. We wrote this plug-in to meet our needs and have chosen to release it (hopefully) for the benefit of others. Please expect a few bugs.
The class we’re using to resize images (requires GD) doesn’t do a particularly good job of compressing the resulting images. Ideally you’d run them through PNGOUT or optimize them in Fireworks in order to ensure the smallest possible file size.
The plug-in looks in the /da-mirf/data folder for the latest (by actual date) version of a .json file and attempts to use that as it’s data source. The filename isn’t important so long as it’s valid and ends with a .json extension.
There is no real documentation at this point as I’m about to hop on a flight to Hong Kong in a few hours. I’m posting this as I’ve been asked by a few colleagues to make the current version publicly available. Expect it to evolve over the coming weeks.
Download and Installation
Caution! The plugin you are about to download is extremely hot — please expect a few bugs.

- Download the DA-MIRF plug-in for WordPress.
- Register and/or login to DeviceAtlas
- Download the current PHP API
- Download your current data file (click on ‘My Account’ then the ‘Downloads’ tab)
- Unzip and copy the PHP API (/Mobi/Mtld/DA/*) to da-mirf/libraries (replace existing ‘/Mobi’ folder)
- Copy to the data.json file into the da-mirf/data folder - the name doesn’t matter, just the .json extension
- Upload everything to your /wp-content/plugins/ folder
- Active the DA-MIRF plug-in within WordPress Admin
- Test using a mobile phone and/or a UA switcher.
To see it in action please visit http://yiibu.mobi.
We are not able to include the DeviceAtlas API or data.json files within the download as neither are available under an open source license. You can however freely download them from the DeviceAtlas site once you’ve registered. Please note: in order to use DeviceAtlas on a live WordPress install you MUST purchase a commercial license.
The DeviceAtlas - Mobile Image Replacement Filter [DA-MIRF] itself is released under the MIT license.
{ 2 comments }
![ready.mobi: score of 5 [Good] It will probably display very well on a mobile phone.](http://bryanrieger.com/wp-content/uploads/2008/11/ready-mobi.png)


