JenLampton on Drupal
Questions & Answers made better – by being made public.
Mobile versions of CCK images (via Imagecache)
Posted by on September 27, 2010
I have a new site that I expect to be regularly accessed from mobile devices. Using Mobile Tools, I’m able to switch themes when a mobile device is detected, which works great. But this site is heavy with images, attached to nodes via CCK imagefield and sized with Imagecache. Ideally, on node view, I would be able to select different Imagecache profiles for my mobile vs desktop theme, but I just can’t figure out how to do that.
Here are the two basic strategies I thought of, but got nowhere with:
- In CCK Display settings for the node, if only there were a “Mobile” option along with “Basic”, “RSS”, “Search” and “Token”… Or can I use Token somehow? I don’t know how to make use of this option
- In Panels, I could create different variants of the node view for mobile vs primary theme, but how do I set “current theme” as the context (or otherwise know that the page is being viewed on a mobile device)?
I’d appreciate any thoughts on how I could accomplish this!
Because all your output is eventually controlled by your theme, you
could handle this with an override of theme_imagecache() in your
mobile theme. Here’s how I’d do it:
1) create mobile versions of each imagecache preset you’d like
replaced (example: thumb and mobile_thumb, full and mobile_full)
2) create a mobiletheme_imacecache function, which works exactly the
same as theme_imagecache, but before just using the preset specified,
it first checks to see if there is a preset with the prefix “mobile_”
and if there is, it uses that instead.
There may be a more elegant solution, but I think this will do the
trick for you.
Not sure if it helps, but the Display Suite module can create custom build modes in which you could set different mobile image cache formatters for each field.
Once the build mode is created, I’m not sure how to specify to use the custom build mode on the mobile site?
Hope that helps