PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Friday, July 29, 2022

[FIXED] How to use next/image show image under project folder with Next.js?

 July 29, 2022     image, next.js     No comments   

Issue

I want to create a component use next/image show a image like

import React from "react";
import Image from "next/image";

type ThumbnailType = {
  image: string;
  alt: string;
  width: string;
  height: string;
};

export const Thumbnail: React.FC<ThumbnailType> = ({
  image,
  alt,
  width,
  height,
}) => {
  return <Image src={image} alt={alt} width={width} height={height} />;
};

When use this component in one page:

import type { NextPage } from "next";
import {
  Thumbnail,
} from "~/components";

const Home: NextPage = () => {
  return (
    <div>
      <Thumbnail
        image="/src/public/product.png"
        alt="nice"
        width="100"
        height="100"
      />
    </div>
  );
};

export default Home;

The product.png image is under the src/public folder. But from browser got this src:

f_auto,c_limit,w_384,q_auto/src/public/product.png

Why?


Solution

You should put public folder in the root directory, not in src folder

your_nextjs_project/public

<Thumbnail
    image="/product.png"
    alt="nice"
    width="100"
    height="100"
/>


Answered By - iamhuynq
Answer Checked By - Marie Seifert (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing