There needs to be retina display integration in the module as supported by the js library. I've wanted to do this from the get go, but i cant seem to find a good way of doing it, or at least I can only find one. I don't like only having one solution to a problem, so I'm asking the community for input.

My one way:

The way i've come up with, for doing this, is by using imagestyles. The problem is mapping them together, and that can only be done using an array map of normal imagestyles and their retina version. Mapping these styles together is, however, a small nightmare UX wise. I would have a dropdown per imagestyle, where the user could select the retina version of "this" imagestyle.

Other options are welcome.

Comments

swim’s picture

In my opinion the Drupal way would be very close to what you have suggested, essentially image styles is the way to go.

Maybe you could extend upon the following?

https://drupal.org/project/resp_img

gnucifer’s picture

Version: » 7.x-1.3-rc1
Issue summary: View changes

Does https://drupal.org/project/picture support custom media queries? In that case it can be done like this example: https://github.com/scottjehl/picturefill#hd-media-queries

    <span data-picture data-alt="A giant stone face at The Bayon temple in Angkor Thom, Cambodia">
        <span data-src="small.jpg"></span>
        <span data-src="small_x2.jpg"      data-media="(min-device-pixel-ratio: 2.0)"></span>
        <span data-src="medium.jpg"        data-media="(min-width: 400px)"></span>
        <span data-src="medium_x2.jpg"     data-media="(min-width: 400px) and (min-device-pixel-ratio: 2.0)"></span>
        <span data-src="large.jpg"         data-media="(min-width: 800px)"></span>
        <span data-src="large_x2.jpg"      data-media="(min-width: 800px) and (min-device-pixel-ratio: 2.0)"></span>
        <span data-src="extralarge.jpg"    data-media="(min-width: 1000px)"></span>
        <span data-src="extralarge_x2.jpg" data-media="(min-width: 1000px) and (min-device-pixel-ratio: 2.0)"></span>

        <!-- Fallback content for non-JS browsers. Same img src as the initial, unqualified source element. -->
        <noscript>
            <img src="small.jpg" alt="A giant stone face at The Bayon temple in Angkor Thom, Cambodia">
        </noscript>
    </span>
lorique’s picture

Unveil has a built in mechanism for this, and it mimics the media queries.

<img src="bg.png" data-src="img1.jpg" />
<img src="bg.png" data-src="img2.jpg" data-src-retina="img2-retina.jpg" />

The important bit here is the data-src-retina, which is where you store the path to the retina image. As @swim and I pointed out it should be solved using imagestyles, somehow mapping imagestyles to each other, so you have a low-res and retina image for styles.

Its important to note that this has nothing to do with the picture module. This should first be implemented as general behavior, and afterwards its worth opening a topic for implementing retina support for the picture module implementation of unveil. This implementation can be found in #2211575, and is not yet closed.

If you want different images for retina displays in the picture module, this should be posed as a feature request to the picture module. The unveil module has one specific task, and that is implementation of the unveil.js library created by Luis Almeida, which can be found here: https://github.com/luis-almeida/unveil/

gnucifer’s picture

What I wanted to say was that retina support is a task for the picture module. I know about data-src-retina as I read the code for unveil.js, but to add support for that in the unveil.module would be to reimplement a poor-mans version of the picture module. As long as there is compatibility between the picture module and unveil (which I believe there is now, with the latest patch in #2211575) there already is retina support. We are already using it in production.

lorique’s picture

@gnucifer

Again, i didn't make the unveil module to support the picture module. I made the unveil module to support standard drupal image handling. The implementation for picture module (Thanks for the patch btw, i will get around to look at it this week) is purely a sidenote, and i am considering putting it in a submodule to the unveil module - called unveil_picture - simply because that seems to be the standard way of handling stuff like that.

gnucifer’s picture

Yes, I understand that the only purpose of the module is to provide integration between unveil.js and drupal. My main point though, I don't know if I made my self clear enough, was that I don't think that you need (or should) add support for the retina feature of unveil.js, but instead provide that feature through the picture integration. So once you have a working integration between unveil and picture, this issue can be closed (I think). But perhaps you already agree on this?

lorique’s picture

I do not.

I don't think making a hard dependency to the picture module is a great idea, and i don't think you should need to download and configure it for your site, unless you have a specific need for some of what it does. The unveil module should have retina support, outside of what picture module does, even if it is a poormans version of what picture module does.

gnucifer’s picture

To implement this you would probably have to (as you probably are aware of):

  • Add an admin interface for creating image style "profiles" of some sort with one retina style associated with the corresponding non-retina image style.
  • Either add a formatter, or performing a lookup based on the current style in the theme function that will get the retina variant.

This is exactly what the picture module does (using formatters) and more! Apart from this it also has support for any pixel-ratio, not just > 1 as in jquery.unveil.js.

I see no reason why you would want to bloat Unveil with functionally that is provided by another module.

The only objections I can think of are:

  • The UI of the picture module is poorly designed and a cause for user confusion, you would prefer a simpler interface, not forcing the user to use a complex module.

Agreed, but the writing some simple instructions how to get retina support by using the picture module could address this. You would basically just follow this https://drupal.org/node/1904690 guide, but instead of 'min-width: xx' just have one breakpoint with "all" (min-width: 0px will also work) and check the multipliers you want support for. And once you get the hang of it, picture is NOT a very complex module at all.

  • You "just" want support for retina, not confuse the user with other things concerning responsive images.

Well, this is a valid point. But first of you will not get as good support for retina (no custom pixel ratios) as the picture module provides, and if a user later on also want responsive images, the two configurations are incompatible and he/she would have to move all the settings in Unveil to the Picture settings format, instead of simply just adding another breakpoint.

lorique’s picture

@gnucifer

I appriciate you spending the time spelling out the con's of doing it in the unveil module, but im fairly certain i wont have to do a lot of work to get it done and i don't think it will bloat the unveil module. I don't want to add all the functionality of the picture module, because the picture module handles a lot of things i really don't care a lot about, such as different image sizes for different screen sizes.

Fiddling with compression/quality rather than imagesizes, and only loading images near or inside the current viewport actually fixes more of the bandwidth problems you're trying to address, than having a lot of different imagesizes matching each screen size and then trying to determine which of them you should use based on media queries.

Unveil module's handling of this should be fairly simple, and not require a formatter but rather an image effect mapping an image style to another imagestyle with a different resolution, and then mapping it up inside the theme function for unveil_image. I think it can be done within a couple of hours, and i plan on looking into it at the end of this week when im off work.

createchlondon’s picture

I would love to this this functionality added to the Drupal Unveil module as retina support is very important.

Okay why don't we take a look at the way Retina.js works, it searches for the same image with @2x appended to the filename. You need to output this as a variable that replaces the "data-src-retina" attribute, if an @2x is not found then it doesn't need to perform anything. This would support the standard functionality of Unveil.js without overcomplicating things.

It would be down to yourself to upload your own @2x images, this could be separate functionality for a separate module but at least this module would be complete.

Me personally I would simply add another image field to my content types specifically for retina images. Please could you respond and let me know if this solution is convenient as it would be the most efficient method of completing the functionality.

createchlondon’s picture

@lorique

In my struggle to make this module work the way I would have hoped I have created a fix for my project. I have modified the code in module.info as follows:

  // Return image URL
  $filename = file_create_url($variables['path']);
  
  // Find the dot in the filename
  $extension = strrpos($filename, '.');
  
  // Create variable to modify original filename to retina file name
  $retinaname = substr($filename, 0, $extension) . '@2x' . substr($filename, $extension);

  $attributes = array('title' => $variables['title'], 'alt' => $variables['alt']);
  // Attributes.
  $attributes += $variables['attributes'];
  $attributes['src'] = file_create_url(drupal_get_path('module', 'unveil') . '/image_placeholder.gif');
  $attributes['data-src'] = $filename;
  $attributes['data-src-retina'] = $retinaname;

This will simply add the @2x image URL to the supported 'data-src-retina' attribute allowing Unveil.js to handle the rest. I currently do not have a fallback support when no retina image is available but in the case of my project I want all images to be retina supported anyway. If we can create a fall back then I think this task will be complete.

Now I just need to find a solution so that retina images can be uploaded to Drupal creating the standard and retina versions for me to make things easier. I would love a solution like imgix.com or a similar system to be integrated with Drupal so that you can upload 1 image and the system will create a URL for the retina image saving you storring 2 files for each image e.g. - cdn.yourwebsite.com/image.jpg?=retinaimage and cdn.yourwebsite.com/image.jpg.