简体   繁体   English

为什么 next/image 仅在本地发布后不调整图像大小?

[英]why next/image is not resizing images after release only locally?

We are using next image for image optimization, we are having very weird issue and we are wondering if some of you faced similiar problem.我们正在使用下一张图像进行图像优化,我们遇到了非常奇怪的问题,我们想知道你们中的一些人是否遇到了类似的问题。

So to begin with in our code base we have code for rendering images which is因此,首先在我们的代码库中,我们有用于渲染图像的代码

imageElements: screenshotImageUrls?.map((imageSrc: string) => {
            return (
              <Image
                src={imageSrc}
                alt=""
                height="190px"
                width="94px"
                quality={100}
              />
            );
          })

When we are on localhost enviroment looks like image resizing is working properly当我们在 localhost 环境中时,看起来图像大小调整工作正常

内在尺寸为:96x170px Intrinsic size is: 96x170px内在尺寸为:96x170px

And when we deploy our app to our domain it looks like resizing is not working anymore and next image is loading full image size what is stored on remote server.当我们将应用程序部署到我们的域时,看起来调整大小不再起作用,下一个图像正在加载存储在远程服务器上的完整图像大小。

在此处输入图像描述 Intrinsic size is: 392x686px内在尺寸为:392x686px

Any idea what can couse this werid behaviour?知道什么会导致这种奇怪的行为吗?

The next/image component's default loader uses squoosh because it is quick to install and suitable for a development environment. next/image 组件的默认加载器使用 squoosh,因为它可以快速安装并且适合开发环境。 When using next start in your production environment, it is strongly recommended that you install sharp by running yarn add sharp in your project directory.在生产环境中使用 next start 时,强烈建议您通过在项目目录中运行 yarn add sharp 来安装Sharp。 This is not necessary for Vercel deployments, as sharp is installed automatically.这对于 Vercel 部署不是必需的,因为Sharp 是自动安装的。

After installing sharp to our project finally image resizing work in production.将Sharp安装到我们的项目后,最终在生产中进行图像调整工作。

Try optimizing your image source URL because as per documentation there is a limit of A maximum of string length of 4,096 for the source and destination values.尝试优化您的图像源 URL 因为根据文档,源值和目标值的最大字符串长度限制为 4,096。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM