Closed (fixed)
Project:
Picture
Version:
7.x-2.x-dev
Component:
Code
Priority:
Major
Category:
Feature request
Assigned:
Reporter:
Created:
12 Mar 2015 at 08:55 UTC
Updated:
16 Oct 2015 at 09:04 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
honza pobořil commentedThis module currently support only
tag, so this is feature request.
Comment #2
honza pobořil commentedMore motivation:
<img src="biggest picture for old browsers" srcset="responzive pictures" sizes="">don't need any JS polyfill necessary, it just download the biggest picture specified in src, so it shows "some" picture with JS disabled or broken.Comment #3
giupenni commentedI agree with rolfmeijer, the module is bad. For the majority of the images on the web,
is the wrong solution.
http://blog.cloudfour.com/dont-use-picture-most-of-the-time/
Comment #4
giupenni commentedhttps://www.drupal.org/node/2348255
Comment #5
attiks commented#2 it depends if you mind double downloads or not
#3 i think "bad" is a bit exaggerated, when we first build this module, sizes was not even available
The way forward similar to D8:
- output img whenever possible
- polyfill can already be disabled
Patches are welcomed
Comment #6
rolfmeijer commentedattiks, if I understand the D8-issue correctly the preferred way is to make this an option, not something that is done automatically, based on some conditions.
Can you please explain what the “Image with sizes” options does? Why is this an option besides the picture mappings. Because to me that sounds like a proper solution to use for the img-only option. Does that make sense or do I misunderstand the functionality of “Image with sizes”?
Comment #7
attiks commented#6 There's no consensus for D8 yet, I think it should be automatic, otherwise site builders have to decide what to use, which will make their job harder.
I added "image with sizes" to the D7 version because we needed it, but the output is still using a picture tag to avoid double downloads.
I think it is doable to output just an img tag when we can, it will probably be a config option to not break older sites, I know some people add css on the picture tag. Initially the option will be disabled by default, but eventually it will be enabled by default.
Comment #8
attiks commentedSince a lot of people are involved, can somebody write a patch. I added an option to use src as fallback, so this sounds like a next logical step.
The current output has to remain unchanged, but feel free to add an option to the admin settings to output only an image tag.
Comment #9
supermoos commentedThis isn't a patch, but put it in your theme's template.php file, and it will output the correct modern markup (https://html.spec.whatwg.org/multipage/embedded-content.html#viewport-ba...), just choose the formatter "Image with sizes", input your sizes string like: "(max-width: 767px) 50vw, 19vw" and check the image styles you want to be outputted in the srcset.
If you use manualcrop you will need this patch: https://www.drupal.org/node/1556244#comment-9244007
This is because the image style needs to define a 'dimensions callback' in order for this function to work properly.
This is a first attempt, so improvements can probably made, and just as note; I removed the width, height from the outputted
<img />-tag markup.Comment #10
attiks commented#9 Nice work, it would be great if you can roll a patch that:
- adds a new option to the settings screen, picture_admin_settings
- changes the output if the option is enabled to output only an image tag when using 'image with sizes'
Comment #11
jnettikHere's a patch that adds a new global setting, and provides logic in
theme_picture_sizes_formatter()to use eithertheme_picture_formatter()which is how it currently works ortheme_image_srcset()depending on that new setting.I did have a question about the duplicate download issue. I'm mostly seeing posts that are a couple years old already. Is there a description of the issue that's current to what browsers currently have implemented? I appreciate any background on this you can provide.
Comment #12
jnettikNever mind about the duplicate download resources. I just found some and understand the issue better now.
Comment #14
attiks commentedThanks all, committed
Comment #17
phm commentedI'm using the "image with sizes" formatter.
When I tick the setting to only use img elements, I get an empty 'w' descriptor for one of the image styles ("w" and "600w"):
<img src="http://path/to/files/styles/work_thumbnail/public/Image_recto.jpg" srcset="http://path/to/files/styles/work_thumbnail__2x/public/Image.jpg 600w, http://path/to/files/styles/work_thumbnail/public/Image.jpg w" alt="" title="" sizes="(max-device-pixel-ratio: 1) 300px, (max-resolution: 96dpi) 300px, (min-device-pixel-ratio: 1.5) 600px, (min-resolution: 192dpi) 600px">Whereas with picture, I get the correct w descriptors ("300w" and "600w"):
<source srcset="http://path/to/files/styles/work_thumbnail/public/Image.jpg?itok=8B02-ATC&timestamp=1442695856 300w, http://path/to/files/styles/work_thumbnail__2x/public/Image.jpg?itok=4FkQJwAW&timestamp=1442695856 600w" sizes="(max-device-pixel-ratio: 1) 300px, (max-resolution: 96dpi) 300px, (min-device-pixel-ratio: 1.5) 600px, (min-resolution: 192dpi) 600px">Comment #18
phm commentedComment #19
wongjn commentedI have encountered another problem with the
imgwithsrcsetoutput option. When selecting more than two image styles, the outputsrcsetattribute will output only the last two styles selected in the list and with the incorrectwdescriptor as comment #17.Edit: It seems this is because all but one of the image styles have not been generated, and thus have no image information attached to them. These non-existed images all have the same empty
wkey so they override each other which is why there is only onesrcsetimage with an emptyw.Edit 2: I've managed to fix this by adapting some code from a comment on this page. I don't know how to post patches so here is a diff instead:
Comment #20
wongjn commentedI'm not sure how to post a patch so here's an updated theme function instead that fixes some issues with image
srcsetoutput.Comment #21
attiks commentedComment #22
jnettikIs the code in #20 aimed to fix the issues in #17? If not can you elaborate on what issues you saw the code fixes?
For the issue in #17, it would be helpful to know what effects are in the image styles you're using. I'm not sure how to create that issue locally.
Comment #23
attiks commentedKeep in mind that inDrupal 7 there are image effects not returning width/height of image, so that might be the reason
Comment #24
jnettik@attiks I tested this with various combinations of image styles in D7 core. Desaturate doesn't have any dimensions defined, but I'm still getting a value for the w selector. It's falling back to the size of the original image.
image_get_info($image_style_uri)shouldn't be trying to pull dimensions from the image style, but from the image itself.Comment #25
attiks commented#24 All effects should implement
dimensions passthroughordimensions callbacksee https://api.drupal.org/api/drupal/modules!image!image.api.php/function/h...Getting dimensions from images means the image has to exists and getting the info out of the image is sloooow. Best to test with a simple resize or crop
Comment #26
phm commentedIn my image styles I used only the "scale" effect, set to 300px width and 600px width. So I would assume that should return an image width.
Comment #27
wongjn commentedComment #28
wongjn commentedI was in a bit of a rush when I commented before (#20) so here's an explanation on what my modifications do.
I added in this bit of code:
This bit of code tries to ensure that an image derivative is generated, because during the code run of the img with srcset option, the images are not requested and their derivatives are not generated. This then causes all the derivatives (apart from one for some reason) to have an empty width.
In
theme_img_srcset, it uses the widths as the key to array, so all other image derivatives override each other into onewdescriptor, meaning only two image URLs get output by that function – one with a validwdescriptor and one with just thewletter and nothing else. This solves #17.I also programed in the instance where the Empty Image option is used, and since it's width can't be 0 (for a true empty image), I manually set its width as 1px.
Comment #29
jelle_sI just noticed. Apparently we committed a patch without fully checking it. The fault is at http://cgit.drupalcode.org/picture/tree/picture.module#n1229
Following lines:
should be changed to something like:
I'll fix it asap.
Comment #30
jelle_sFixed in latest dev.
Comment #32
rolfmeijer commentedWow, this is really brilliant. I just implemented the last commited dev version and it works great.
Just one tiny remark, on the page the help-text for the "Image with sizes" output method says you get double downloads. As far as I know, this is only true if you use Picturefill. (See f.i. https://css-tricks.com/responsive-images-youre-just-changing-resolutions...).
Suggestion for the text:
"srcset on Image tag" creates the correct markup, however in combination with Polyfill you get double downloads.
Thank you all very much anyway!