Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to present a blurred version of an image in NextJS as it's being downloaded?

I'm looking for a similar effect as this one below:

blur image effect

I have done something similar with Gatsby, but I'm wondering if this is possible to do with NextJS?

like image 949
Mike K Avatar asked Dec 07 '22 10:12

Mike K


2 Answers

For version above 10.2 Nextjs is providing built in blur image in Image component. After spending hours I found this article

First you need to update your nextJs app to 10.2.4 or above version.

yarn add [email protected]

Then implement your nextJs Image component with two addtional props blurDataURL and placeholder. Check the code example below.

<Image
   className="image-container"
   src="/images/high-quality-image.jpg"
   width={250}
   height={240}
   quality={75}
   blurDataURL="/images/path-to-blur-image.jpg"
   placeholder="blur"
/>

Next.js Update:

Next.js now support placeholder="blur" you can use it in the image component:

<Image src={author} alt="Picture of the author" placeholder="blur" />
like image 102
DevAB Avatar answered Dec 31 '22 03:12

DevAB


You can do it without using an external library with not much code.

https://codepen.io/darajava/pen/GRZzpbB?editors=0110

I added animations in there too on load. The image will fit to the width of its parent container. Usage is simple:

<LoadImage largeImageSrc={url} smallImageSrc={url} />
like image 35
Dara Java Avatar answered Dec 31 '22 01:12

Dara Java