desandro / imagesloaded

:camera: JavaScript is all like "You images done yet or what?"
https://imagesloaded.desandro.com
MIT License
8.88k stars 1.15k forks source link

Loading image from object tag #285

Closed Tashows closed 2 years ago

Tashows commented 5 years ago

I came across the need to load images from an object tag. After not finding a good enough solution elsewhere, I thought it would be a nice addition to the plugin. For this to work there are two requirements: 1) There has to be an option objects: true set in the imagesLoaded call, 2) The object tags need to have type="image/***" attribute specified (to avoid unnecessary loading of objects).

There might be more issues that need to be covered if this is to be merged, however I thought I'd share in case anyone else needs that functionality. Any thoughts welcome.

pyrsmk commented 5 years ago

Can you explain what the cases where you need to use object instead of img ?

Tashows commented 5 years ago

@pyrsmk, I wanted to fetch image from standard-patterned remote urls. However some of those images might not exist, so there is an alternative url that always serves an image (lower res). So I used object and image tags to create this fallback behavior without js. Then I needed to check if object images were loaded to initialize a js plugin that needs to resize based on the images.

pyrsmk commented 5 years ago

What do you mean about 'standard-patterned remote urls' ? Like picsum service is delivering ?

Tashows commented 5 years ago

@pyrsmk I mean they have a fixed pattern. Yes, like picsum. Specifically I am referring to Youtube thumbnails urls. You can get the thumbnail by replacing the video id in a specified url. There are different urls for different versions (resolution). Older videos tend to not have high res thumbnails, so I had to fallback to the default one. Using object and image tags keeps it simple as it's an html-only solution.

pyrsmk commented 5 years ago

Ah ok, thanks. I understand what you're trying to achieve.

desandro commented 5 years ago

Thanks for this PR. Add a 👍 reaction to this issue if you would like to see this feature added. Do not add +1 comments — They will be deleted.

desandro commented 2 years ago

This PR didn't get enough interest to warrant adding to the master branch. Thanks again for your effort. Sorry to pass on this one.