sal0max / grav-plugin-shortcode-gallery-plusplus

A Shortcode extension to add sweet galleries with a lightbox to your Grav website.
MIT License
33 stars 8 forks source link

Simplify `srcset`, force the use of the thumbnail #37

Closed ghost closed 1 year ago

ghost commented 1 year ago

Hello ! ^^ I'm sorry, but there's something wrong. In my PR #32, I wanted to make a very clean use of srcset. So, I give the true estimated width of the image to the browser (sizes="#{estimated_thumb_width}px"), so that it can chooses the image that best fits the pixel ratio of the device (DPR).

However, there are three problems:

  1. It generates twice as many images (for DRP=2 and DPR=3).
  2. As the size of the images increases, the interest in generating thumbnails decreases.
  3. The devices with DPR=4 (and I discovered that it exists [1]) do not use the thumbnail.

Note that Grav inserts the original image in the srcset, that's why DRP=4 devices use it.

So, I think we need to simplify things:

  1. Generate only one thumbnail in the srcset, of a size chosen by the admin (I have reintroduced the resizeFactor parameter).
  2. Force its use by lying to the browser (sizes="1px"), because Grav adds the original image to srcset.

To sum up:

In any case, the attributes width and height define the actual display dimensions of the image. So if an RSS agregator uses srcset (or if Javascript is not enabled), a gallery similar to what JG does will be displayed, but unjustified. Note: Same if an RSS aggregator uses width and height attributes.

By the way, I changed the default value of resizeFactor from 1.5 to 2. I think this is the most optimal value (tested on phones with DPR=3), but you can modify it if you want. ^^

That's it. I'm sorry to come back to this, but it looks better to me. Have a nice day !

[1] https://www.mydevice.io/#compare-devices

ghost commented 1 year ago

🤔 Up ? ^^

vparmeland commented 1 year ago

@sal0max ?