在 Node.js 中,可以使用sharp模块来处理图片。首先,确保已经安装了sharp模块:

npm install sharp

然后,可以使用以下代码来旋转图片90度:

const sharp = require('sharp');

sharp('input.jpg')
  .rotate(90)
  .toFile('output.jpg')
  .then(() => {
    console.log('Image rotated successfully');
  })
  .catch((error) => {
    console.error('Error rotating image:', error);
  });

在上面的代码中,将input.jpg替换为要旋转的图片路径。旋转后的图片将保存为output.jpg。可以根据需要修改文件路径和旋转角度。

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

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

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