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:
It generates twice as many images (for DRP=2 and DPR=3).
As the size of the images increases, the interest in generating thumbnails decreases.
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:
Generate only one thumbnail in the srcset, of a size chosen by the admin (I have reintroduced the resizeFactor parameter).
Force its use by lying to the browser (sizes="1px"), because Grav adds the original image to srcset.
To sum up:
Advantage of this solution: Only one thumbnail is generated per image, which will always be used.
Disadvantage: The use of srcset is less clean, because setting sizes to 1px is a bit of a cheat.
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 !
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:
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:
srcset
, of a size chosen by the admin (I have reintroduced theresizeFactor
parameter).sizes="1px"
), because Grav adds the original image tosrcset
.To sum up:
srcset
is less clean, because settingsizes
to1px
is a bit of a cheat.In any case, the attributes
width
andheight
define the actual display dimensions of the image. So if an RSS agregator usessrcset
(or if Javascript is not enabled), a gallery similar to what JG does will be displayed, but unjustified. Note: Same if an RSS aggregator useswidth
andheight
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