question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Wrong dimensions: take picture elements into account?

See original GitHub issue

Hi,

I like the simplicity of this lib. I recognized, that the lib doesn’t handle <picture> elements properly in the sense, when I use the <picture> element for art directed images – this means, I have different resolutions and crop sizes of the image based on the device size – it could lead to distorted image (dimensions).

For example: My mobile image is a crop of the desktop image showing only a detail of it with the dimension 10:8 and the desktop image is 16:9.

When I use the 10:8 as my default <img /> within the <picture /> element, but I am on the desktop view and click on the image, then medium-zoom uses the default image from <img />. But as they have different dimensions (10:8 vs 16:9) the image is distorted (it has mapped the 10:8 to the 16:9 dimension as the default image is 10:8 but the dimensions medium-zoom is using are based on the responsive image on desktop with the dimensions of 16:9).

So it even doesn’t work when I use the data-zoom-target attribute. If the data-zoom-target image has a different dimension to the current visible one, it is distorted too.

Example of a picture element:

<picture >
    <source
        media="(min-width: 880px)"
        srcset="./../assets/img/home/example-guy_d.jpg"> <!-- may has a dimension of 16:9 -->
    <img
        class="o-section-stock__photo-img"
        src="./../assets/img/home/example-guy_m.jpg" <!-- may has a dimension of 10:8 -->
        alt="…"
        data-zoom="medium-zoom"
    >
</picture>

I know, it is complicated. I’m not sure if there is a simple solution for that. My first idea was that medium-zoom could read the srcset and decide which image it should use/is the current visible one on the screen and use it. But I think it will be a longer project with all the browser polyfills needed etc.

So maybe the easiest would be that medium-zoom takes the dimensions of the data-zoom-target into account when it uses this as the image source. So it would be a simple workaround for picture elements to use the data-zoom-target. But of course, it still needs a way to scale from dimension A to B … but maybe easier than hacking around with srcset and all it’s -maybe- possibilities …

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:3
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

11reactions
knynkwlcommented, Mar 25, 2019

I’m running into a similar problem. I have 1:1 square thumbnails, but want the HD image to respect the dimensions of the actual image. Instead when clicking the thumbnail, I get a 1:1 HD image.

3reactions
mimamuhcommented, Dec 14, 2017

Hi @francoischalifour, thanks for your answer. I already saw the post. I think, srcset alone wouldn’t solve the issue. Because the issue is more, that medium-zoom takes the dimension from the current visible image. When I use picture then the dimensions may be different because of art direction decisions.

For me it would be fine when medium-zoom always use the default image of the pictrue element which is basically the <img> element within <picture>. But then it has to figure out dynamically the dimensions from the <img> element when it zooms it, because they may differe … Maybe I just post a repro next week to demonstrate you the issue. 😃

Read more comments on GitHub >

github_iconTop Results From Across the Web

Wrong image size when placing - Adobe Support Community
Yes, it is normal to resize based on the physical dimensions -- this is because smart objects can work in different resolutions and...
Read more >
Use explicit width and height on image elements - GTmetrix
Images and/or videos that do not have explicit width and height attributes can cause large layout shifts as your page loads.
Read more >
Snagit 2021 loads again png images with wrong dimensions
Right click the original image and then select Get Info in Finder; note the dimensions of the image; Right click the new image...
Read more >
How to change dimension of image - YouTube
In many competitive exams like GATE, SSC,BOARD exams scan image of our photocopy and signature is required with width x height format so...
Read more >
2023 Social Media Image Sizes for All Networks [CHEATSHEET]
Even though the dimensions are in a square format, Instagram profile photos are displayed as a circle. Make sure any elements you want...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found