📜  节点吉普 |旋转

📅  最后修改于: 2022-05-13 01:56:41.965000             🧑  作者: Mango

节点吉普 |旋转

介绍
rotate()函数是 Nodejs 中的内置函数| Jimp 顺时针旋转图像并且图像的尺寸保持不变。
句法:

rotate(r, mode, cb)

范围:

  • r - 此参数存储图像的旋转角度。
  • mode – 这是存储缩放方法的可选参数。
  • cb – 这是编译完成时调用的可选参数。

输入图像:

第一步:搭建环境

npm init -y

第 2 步:安装jimp

npm install jimp --save

示例 1:

javascript
// npm install --save jimp
// import jimp library to the environment
var Jimp = require('jimp');
 
// User-Defined Function to read the images
async function main() {
  const image = await Jimp.read
('https://media.geeksforgeeks.org/wp-content/uploads/20190328185307/gfg28.png');
 
// rotate Function having a rotation as 55
  image.rotate(55)
  .write('rotate1.png');
}
 
main();
  console.log("Image Processing Completed");


javascript
// npm install --save jimp
// import jimp library to the environment
var Jimp = require('jimp');
 
// User-Defined Function to read the images
async function main() {
    const image = await Jimp.read
('https://media.geeksforgeeks.org/wp-content/uploads/20190328185333/gfg111.png');
 
// rotate Function having rotation angle as 99, mode and callback function
    image.rotate(99, Jimp.RESIZE_BEZIER, function(err){
        if (err) throw err;
    })
        .write('rotate2.png');
}
 
main();
  console.log("Image Processing Completed");


输出:

示例 2:使用 mode 和 cb(可选参数)

javascript

// npm install --save jimp
// import jimp library to the environment
var Jimp = require('jimp');
 
// User-Defined Function to read the images
async function main() {
    const image = await Jimp.read
('https://media.geeksforgeeks.org/wp-content/uploads/20190328185333/gfg111.png');
 
// rotate Function having rotation angle as 99, mode and callback function
    image.rotate(99, Jimp.RESIZE_BEZIER, function(err){
        if (err) throw err;
    })
        .write('rotate2.png');
}
 
main();
  console.log("Image Processing Completed");

输出:

参考: https://www.npmjs.com/package/jimp