{"title":"Node.js 图片旋转:使用 Sharp 库旋转图片 90 度","description":"使用 Node.js 的 Sharp 库轻松旋转图片 90 度。本文提供详细的代码示例,展示如何加载图片、旋转并保存到新文件。","keywords":"nodejs, 图片旋转, sharp, 图像处理, 90度旋转, 图像库, node.js 库, 图片操作","content":"要在 Node.js 中旋转图片 90 度,你可以使用 Sharp 库。安装 Sharp 库可以使用以下命令:\n\n\nnpm install sharp\n\n\n然后,可以使用以下代码来旋转图片 90 度:\n\njavascript\nconst sharp = require('sharp');\n\nsharp('input.jpg')\n .rotate(90)\n .toFile('output.jpg', (err, info) => {\n if (err) {\n console.log(err);\n } else {\n console.log('图片旋转完成');\n }\n });\n\n\n这将从名为input.jpg的文件中读取图片并将其旋转 90 度,然后将旋转后的图片保存为output.jpg文件。你可以根据需要修改输入和输出文件的路径。"}

Node.js 图片旋转:使用 Sharp 库旋转图片 90 度

原文地址: https://www.cveoy.top/t/topic/pwRE 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录