Skip to content
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

Add option to generate blurry placeholders #30

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

lucasdinonolte
Copy link

Hi there, first of all thanks for this amazing vite plugin, I'm using it a bunch.

Context

I often found myself in the situation where I wanted to roll my own lazy loading using IntersectionObserver and show a blurry version of the image until the original image is loaded in.

What this PR does

  • adds the generateBlurryPlaceholder option to the preset configuration
  • if set, the generateBlurryPlaceholder option will generate a 20px wide base64-inlined PNG of the image and add it to the placeholder key of the last item in the returned image array
    • this follows the same assumption as the inferDimensions option, which is also added to the last returned image, because this is likely the item that'll be used on the img tag in a picture scenario

Caveats / Out of Scope

  • Adding placeholder as a key to the returned ImageAttrs makes the object deviate from valid HTML image attributes, so you couldn’t simple prop-spread them into an img tag. So we might want to find a better place to put the placeholder
  • This PR only adds the blurry-image placeholder strategy. We might consider adding multiple strategies such as "dominant color" etc.

Copy link

netlify bot commented Nov 28, 2023

Deploy Preview for image-presets failed.

Name Link
🔨 Latest commit 0728319
🔍 Latest deploy log https://app.netlify.com/sites/image-presets/deploys/6565b46b2454050008d6a28e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant