JavaScript 编写的图像处理库 Jimp

码农软件 · 软件分类 · 图形/图像处理 · 2019-09-05 12:56:38

软件介绍

Jimp 是一个使用 JavaScript 编写的用于 Node 的图像处理库,具有零依赖的特性。

安装

npm install --save jimp

示例代码

var Jimp = require("jimp");
// open a file called "lenna.png"
Jimp.read("lenna.png", function (err, lenna) {
    if (err) throw err;
    lenna.resize(256, 256)            // resize
         .quality(60)                 // set JPEG quality
         .greyscale()                 // set greyscale
         .write("lena-small-bw.jpg"); // save
});

基本用法

Jimp.read("./path/to/image.jpg").then(function (image) {
    // do stuff with the image
}).catch(function (err) {
    // handle an exception
});

对图像操作的一些方法

/* Resize */
image.contain( w, h[, alignBits || mode, mode] );    // scale the image to the given width and height, some parts of the image may be letter boxed
image.cover( w, h[, alignBits || mode, mode] );      // scale the image to the given width and height, some parts of the image may be clipped
image.resize( w, h[, mode] );     // resize the image. Jimp.AUTO can be passed as one of the values.
image.scale( f[, mode] );         // scale the image by the factor f
image.scaleToFit( w, h[, mode] ); // scale the image to the largest size that fits inside the given width and height
// An optional resize mode can be passed with all resize methods.
/* Crop */
image.autocrop([tolerance, frames]); // automatically crop same-color borders from image (if any), frames must be a Boolean
image.crop( x, y, w, h );         // crop to the given region
/* Flip and rotate */
image.flip( horz, vert );         // flip the image horizontally or vertically
image.mirror( horz, vert );       // an alias for flip
image.rotate( deg[, mode] );      // rotate the image clockwise by a number of degrees. Optionally, a resize mode can be passed. If `false` is passed as the second parameter, the image width and height will not be resized.
image.exifRotate();               // JPEG images with EXIF orientation data will be automatically re-orientated as appropriate.

本文地址:https://codercto.com/soft/d/13928.html

共享经济大趋势

共享经济大趋势

倪云华 虞仲轶 / 2016-1-1 / 49.00

2015年互联网界乃至整个商界的最热门字眼,恐怕就是“共享经济”了。共享经济模式正以前所未有的速度与规模席卷全球。那么,共享经济为什么会产生?其本质是什么?共享经济会为我们带来什么价值?成功的共享经济商业模式是怎样的?如何管理和运作一家共享经济企业?在未来,共享经济还将面临哪些挑战?共享经济的下一个发展机会在哪里?传统经济又该如何应对? 作为国内第一本系统性阐述共享经济的书籍,本书通过对全球......一起来看看 《共享经济大趋势》 这本书的介绍吧!

SHA 加密
SHA 加密

SHA 加密工具

html转js在线工具
html转js在线工具

html转js在线工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试