Open 55555-Jyeon opened 6 months ago
"use client";
import type { NextPage, InferGetStaticPropsType } from "next";
import style from "./page.module.css";
import Image from "next/image";
import profile from "../../public/profile.jpg";
import { getPlaiceholder } from "plaiceholder";
import { useRouter } from "next/navigation";
import fs from "fs/promises"; // Node.js 14.0.0 이상에서는 fs/promises를 사용할 수 있습니다.
export const getServerSideProps = async () => {
// 이미지 파일을 읽어서 Buffer로 전달
const imagePath = "./public/profile.jpg";
const imageBuffer = await fs.readFile(imagePath);
// Remote Image (from external url or relative url like `/my-image.jpg`)
const remoteImageProps = await getPlaiceholder(imageBuffer);
return {
props: {
remoteImageProps,
},
};
};
const Home: NextPage<InferGetStaticPropsType<typeof getServerSideProps>> = ({
remoteImageProps,
}) => {
const router = useRouter();
return (
<main className={style.main}>
<div className={style.ImageContainer}>
<Image
onClick={() => router.push("/Amy")}
placeholder="blur"
blurDataURL={remoteImageProps.base64}
fill
src={profile.src} // 이미지 소스를 remoteImageProps에서 가져오도록 수정
style={{
objectFit: "cover",
}}
className={style.profile}
alt="profile image"
/>
</div>
<div className={style.textbox}>
<p>JUYEON OH</p>
<p>FE DEVELOPER</p>
</div>
<p className={style.copyright}>
copyright © all rights reserved to juyeonOH
</p>
</main>
);
};
export default Home;
참고해서 위와 같이 작성했는데 에러 발생.. 🥹 일단 패스..
⬇️ install
reference site → https://www.yzlow.com/progressive-image-loading-with-nextjs