The issue of 'serving images to devices no larger than they can handle' is simple in principle, but difficult in practice. in principle it's:
a: detect the browsers maximum resolution (if possible)
b: cross-reference that with the sizes that you want to output and output the image (caching would be really nice here).
c: allow the browser to cache the image.
In practice though it's problematic. There are two basic methods:
a: The javascript approach
pros:
it's simple, set a cookie or send the resolution via ajax to the server
cons:
it's problematic and browser dependant. If the cookie (lets say we're using a cookie) is not already sent, then it is set by the javascript. The javascript may not be executed before the images are requested (browsers tend to be asynchronous and do a few things at a time). This could mean that the first time a user on an iphone browses a page he gets the massive images, and since the images are cached on the browser, that's all he gets. Additionally, if the images are resized and cached in the same request that gets the initial HTML for the page (the way CGSmartImage currently behaves) then there may be no resolution data for the program to use to resize the image.
b: Use a web service approach
- on request grab the server details send them to another service to do a database lookup and return the device capabilities.
pros:
- it happens on initial request of the HTML, so that if the data in the web service is up-to-date the rest of the image processing will have the resolution information to play with.
- this request info can be cached for performance purposes so that every request to your page does not have to go to the remote web service.
cons:
- it depends on the accuracy of the web service, and the throughput of your outgoing host (and whatever QOS stuff has been setup).
- it is extra overhead on each request, at least (when using caching) until a reasonable database of your most frequent devices is built up.
Since the goal of CGSmartImage is primarily to improve performance and make image processing simpler, not necessarily to make the 'developers life easier'... if I were to implement adaptive images into CGSmartImage I would probably go with the second approach, and chose a free (and untested by me at this time) web service like:
http://www.deviceidentifier.com/