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

Placeholder support #189

Open
pi0 opened this issue Feb 15, 2021 · 17 comments · Fixed by #477
Open

Placeholder support #189

pi0 opened this issue Feb 15, 2021 · 17 comments · Fixed by #477
Labels
enhancement New feature or request

Comments

@pi0
Copy link
Member

pi0 commented Feb 15, 2021

Basic placeholder property is currently supported for <NuxtImg> (via #477).

Usage: This will auto-generate a URL from same source and 10x10 dimensions:

<nuxt-img src=".." placeholder>

It is also possible to give a custom placeholder (data)URL as a string or an array [width, height, quality] to customize URL generation behavior.

The original image will be loaded during hydration and after mounted.

Future enhancements:

  • Fetch and inline placeholder as data: url
  • Support smoother blurry versions when possible (depends on provider)
  • Start loading images in parallel to hydration.
@shadow81627
Copy link
Contributor

shadow81627 commented Apr 26, 2021

I use vuetify image component for the lazy loading source and generate a small 10 pixel image.

<v-img
    :lazy-src="$img(src, { width: 10, quality: 70 })"
    :src="$img(src, { quality: 70, height: 500 })"
    height="500"
></v-img>

@Rigo-m
Copy link

Rigo-m commented Oct 11, 2021

Any ETA for this?

@creazy231
Copy link

also would really like to see such a feature 👍

@agnelnieves
Copy link

same here

@omp-git
Copy link

omp-git commented Feb 20, 2022

please merge this cool feature :)

@pi0 pi0 unpinned this issue Jun 20, 2022
@pi0 pi0 closed this as completed in #477 Jun 21, 2022
@pi0 pi0 reopened this Jun 21, 2022
@pi0 pi0 changed the title support placeholder Placeholder support Jun 21, 2022
@mrleblanc101
Copy link

mrleblanc101 commented Jul 15, 2022

@pi0 Why is the default placeholder 10x10 ?
Shouldn't it preserve the aspect-ratio of the original image ?
Currently it cause major layout shift.
I guess I could set the ratio using :placeholder=[width, height], except that my Images come from .yml fetched by Nuxt-content so I don't know their dimension and they are not all the same.

Placeholder image:
Capture d’écran, le 2022-07-15 à 00 01 42

Source image:
Capture d’écran, le 2022-07-15 à 00 01 38

@mrleblanc101
Copy link

mrleblanc101 commented Jul 15, 2022

Otherwise it works well for static image.

Source image:
Capture d’écran, le 2022-07-15 à 00 05 16

Placeholder image:
Capture d’écran, le 2022-07-15 à 00 05 21

@enricodeleo
Copy link

Is there any way I can tell placeholder to respect preset ?

@Flo2315
Copy link

Flo2315 commented Aug 17, 2022

Hi @pi0
Nice feature 🚀, but it doesn't seem to work with the cloudimage provider.

@vedmant
Copy link

vedmant commented Oct 6, 2022

Is there any way to add a placeholder globally and that's a data url like: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=

@Kolobok12309
Copy link
Contributor

By src code is not worked with srcset(browser ignore src and use srcset) and load full-size img for mobiles in parallel

onMounted(() => {
if (placeholder.value) {
const img = new Image()
img.src = mainSrc.value
img.onload = () => {
imgEl.value.src = mainSrc.value
placeholderLoaded.value = true
}
}
})

@Kolobok12309
Copy link
Contributor

@mrleblanc101
We use imgproxy and if i set :placeholder=[10, 0, 80] imgproxy save aspect-ratio with width 10px
Mb your provider has something similar

@mtzrmzia
Copy link

Otherwise it works well for static image.

Source image: Capture d’écran, le 2022-07-15 à 00 05 16

Placeholder image: Capture d’écran, le 2022-07-15 à 00 05 21

@mrleblanc101 I have the same issue, did you fix it?

@ekkaiasmith
Copy link

It would be nice if the placeholder could be a base64 sent in HTML to the client rather than an additional asset to load.

@pi0
Copy link
Member Author

pi0 commented Oct 23, 2023

For quick history, we used to load image meta to find aspect ratio using image-meta and also fetch the contents using async data and inline base64 version in earlier versions of image v0. This feature was rolled back due to instability. Also thinking to support a pluggable way to support different algorithms for blurry image other than lowres base64.

If someone is interested, a PR is welcome to add back this feature via an experimental flag.

@pi0
Copy link
Member Author

pi0 commented Jan 31, 2024

/cc @farnabaz

@chrisjansky
Copy link

@mrleblanc101 said:
@pi0 Why is the default placeholder 10x10 ?
Shouldn't it preserve the aspect-ratio of the original image ?

+1 for preserving aspect ratio of source images. Any progress on this? 🙏

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

Successfully merging a pull request may close this issue.