-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Device Pixel Ratio (DPR) support for Picture tag #469
Comments
Hi Ryan, I'm not aware of any current plans to change how the That said, I may be missing something about your requirements and have a follow-up question if you don't mind? In your example, are you intending to load a completely different image (or different transformation options) on screens with higher device pixel ratios, or just to use larger dimensions with larger DPR screens either by explicitly changing the width and height, adding the I ask because if the same image is used each time and only the dimensions will change, my understanding is that browsers will automatically take the device's pixel ratio into consideration when looking at a simple srcset, and will implicitly multiply the 'normal' CSS dimensions by the DPR when choosing which image to use - am I not correct about that, or is there another reason to be more explicit with the media query? Or to ask another way, is there a practical difference between :
and
? |
Hi igy, As far as I know, the CSS <html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<picture>
<source
media="(max-width: 600px) and (min-resolution: 2dppx)"
srcset="https://res.cloudinary.com/hfiohoooe/image/upload/q_auto/f_auto/dpr_2,w_500/v1/models/amel-super-maramu">
<source
media="(max-width: 600px)"
srcset="https://res.cloudinary.com/hfiohoooe/image/upload/q_auto/f_auto/w_500/v1/models/amel-super-maramu">
<source
srcset="https://res.cloudinary.com/hfiohoooe/image/upload/q_auto/f_auto/w_100/v1/models/amel-super-maramu">
<img
src="https://res.cloudinary.com/hfiohoooe/image/upload/q_auto/f_auto/v1/models/amel-super-maramu" style="width: 500px">
</picture>
<picture>
<source
media="(max-width: 600px)"
srcset="https://res.cloudinary.com/hfiohoooe/image/upload/q_auto/f_auto/w_500/v1/models/amel-super-maramu">
<source
media="(max-width: 1200px)"
srcset="https://res.cloudinary.com/hfiohoooe/image/upload/q_auto/f_auto/dpr_2,w_500/v1/models/amel-super-maramu">
<source
srcset="https://res.cloudinary.com/hfiohoooe/image/upload/q_auto/f_auto/w_100/v1/models/amel-super-maramu">
<img
src="https://res.cloudinary.com/hfiohoooe/image/upload/q_auto/f_auto/v1/models/amel-super-maramu" style="width: 500px">
</picture>
</body>
</html> On my MacBook running Chrome 87:
If the browser was accounting for pixel density, I would expect the second picture tag to load the 1000 pixel image when the viewport is less than 600px wide (because it would be looking at the 1200px media query). If you agree with my assessment, could you please pass on my original feature request to the SDK team? Also, would you be willing to accept a PR if I implemented it myself? Side rabbit hole: I feel like I must be doing something fundamentally wrong, since I can't be the first one of your users who has tried to support high density screens. Do you have any idea how others approach this problem? |
Hi Ryan, Thanks for the additional information - After reading the example you provided, I think I was thinking of a simple srcset without media queries involved - my experience there was that browsers take the CSS/logical pixel width and then add a multiplier for the DPR when choosing which of the offered images to show. I performed a quick test in Chrome also on a Macbook Pro, and created an image tag with widths 250, 500, 750, 1000, 1250, 1500 - (i.e In the context of the To answer your other question, most implementations that I've seen use either a relatively simple image tag with an srcset, use a client-side framework to build the image tags (sometimes a third-party SDK, sometimes one of our client-side SDKs), or use our responsive() javascript method to replace Regards, |
Yes, an Client-side solutions have the same problem (trading download of the CSS for download of the script). I try to avoid client-side javascript unless absolutely necessary; it's amazing how far you can get with just modern HTML and CSS. Thank you for opening the feature request. I may take a stab at implementing it myself, and if I do I'll open a PR. |
Hi Ryan, We don't have a If you do send something, I recommend that to aid the SDK team in reviewing it, it includes tests and that it's fully backwards-compatible (i.e that existing users of the picture() method will be able to apply your change without changing any of their own code or causing a breaking change in what that code produces). Even if the SDK team aren't able to accept it for some reason, having a PR here would allow you to apply it as a patch easily, and could let other customers do the same if they have the same requirements as you Regards, |
Feature request for Cloudinary_NPM SDK
Explain your use case
I'd like to be able to automatically generate
source
variants based on DPR inside apicture
tag. Currently, we can usecloudinary.picture()
to generate apicture
tag, but there doesn't seem to be a way to factor DPR into either thesrcset
URLs nor the media query.Describe the problem you’re trying to solve
High-resolution screens, such as those on many Apple products, require higher-resolution images to display at full quality than the size in CSS pixels would suggest. There are (at least) two mechanisms in HTML and CSS to solve this: the
srcset
attribute ofsource
(orimg
) tags can specify multiple URLs (each tagged with the pixel density), or you can use themin-resolution
CSS media query. I'd like to be able to generatepicture
tags that look like these:srcset example
media query example
As far as I can tell, neither of these are possible to generate using the options to the picture function, invoked like this on my Node backend:
Do you have a proposed solution?
I propose we could generate the first one with a new attribute like this:
Or generate the second one with something like this:
The second proposal more closely matches the existing interface of the
picture
function, is more flexible, and is probably easier to implement, but it requires repeating the DPR twice in each source specification (once asmin_resolution
and once asdpr
in the transformation). In my mind, the entire point of this library is to save us from tedious and error-prone boilerplate, so I don't like having to repeat that. Thus, I think the first proposal is probably the better choice.Is there any plan to implement a solution like this? If not, would you accept a PR that implements one of these? Thanks!
The text was updated successfully, but these errors were encountered: