简体   繁体   English

我可以在 React js 中使用 Sharp 图像处理库吗?

[英]Can I use Sharp image processing library in React js?

I try to use Sharp image processing in my create react app.我尝试在我创建的 React 应用程序中使用Sharp图像处理。 But it sends a error但它发送错误在此处输入图像描述

This is my code这是我的代码

import sharp from 'sharp';

const buffer = await sharp(req.file.buffer)
          .resize({ width: 250, height: 250 })
          .extend({
            top: 10,
            bottom: 10,
            left: 10,
            right: 10,
            background:  '#d7d8de'
          })
          .png()

Edit: I'm using Node.js version 12.18.0编辑:我正在使用 Node.js 版本 12.18.0

No. 不。

Sharp uses the node.js runtime as well as binary executable code that is installed on the host system. Sharp 使用 node.js 运行时以及安装在主机系统上的二进制可执行代码。 All this means that Sharp does not work in a web browser.所有这些都意味着 Sharp 无法在 Web 浏览器中运行。

For client side processing, use Canvas API: https://www.w3schools.com/html/html5_canvas.asp对于客户端处理,使用 Canvas API: https://www.w3schools.com/html/html5_canvas.asp

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

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