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

Not working on latest version of nextjs #15

Open
Stevemoretz opened this issue Oct 2, 2023 · 2 comments
Open

Not working on latest version of nextjs #15

Stevemoretz opened this issue Oct 2, 2023 · 2 comments

Comments

@Stevemoretz
Copy link

Stevemoretz commented Oct 2, 2023

None of the versions of this library are working so here's a quick replacement as I couldn't find any, I made my own but I don't have the time to turn it into a library I put my code here and anyone can make it into a library or maybe this repo adapts it.

How to make it work

All credits of the functionality goes to https://gist.github.com/mattiaz9 I was only able to make this work thanks to his function at:
https://gist.github.com/mattiaz9/53cb67040fa135cb395b1d015a200aff

  1. Copy and paste that into your project under a file named: blurHashToDataURL.ts
  2. Copy and paste my component in a file named: ImageHash.tsx
import {blurHashToDataURL} from "@src/lib/blurhash/blurHashToDataURL";
import Image from "next/image";
import {useMemo} from "react";

type Props = {};

export default function ImageHash({
    blurhash,
    ...props
}: React.ComponentProps<typeof Image> & {blurhash?: string}) {
    const base64BlurHash = useMemo(() => {
        if (blurhash) {
            return blurHashToDataURL(blurhash);
        }
        return null;
    }, [blurhash]);

    return (
        // eslint-disable-next-line jsx-a11y/alt-text
        <Image
            placeholder="blur"
            blurDataURL={base64BlurHash || undefined}
            {...props}
        />
    );
}

Install blurhash using npm|yarn|bun.

Usage example

Not that ImageHash's syntax is exactly the same as Image component from nextjs it just adds one new prop: blurhash pass your blurhash and you're done.

<ImageHash
    blurhash={value.photo_hash}
    src={`/image.png`}
    width={500}
    height={375}
/>
@jelling
Copy link

jelling commented Apr 21, 2024

@ivansevillaa please consider either adopting the fix or shutting this repo down and deprecating the NPM package.

I lost several hours trying to debug this issue and I'm certain others have as well.

@3ternal
Copy link

3ternal commented Oct 11, 2024

Same problem here. The proposed solution probably works, but I didn't want to fiddle with modifying the package, so I ended up using this package: https://github.com/mcnaveen/blurhash-base64

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

No branches or pull requests

3 participants