Jimp JavaScript 编写的图像处理库

开源网站开源项目 24-04-14 14:11:35

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

安装

npminstall--savejimp

示例代码

varJimp=require("jimp");//openafilecalled"lenna.png"Jimp.read("lenna.png",function(err,lenna){if(err)throwerr;lenna.resize(256,256)//resize.quality(60)//setJPEGquality.greyscale()//setgreyscale.write("lena-small-bw.jpg");//save});

基本用法

Jimp.read("./path/to/image.jpg").then(function(image){//dostuffwiththeimage}).catch(function(err){//handleanexception});

对图像操作的一些方法

/*Resize*/image.contain(w,h[,alignBits||mode,mode]);//scaletheimagetothegivenwidthandheight,somepartsoftheimagemaybeletterboxedimage.cover(w,h[,alignBits||mode,mode]);//scaletheimagetothegivenwidthandheight,somepartsoftheimagemaybeclippedimage.resize(w,h[,mode]);//resizetheimage.Jimp.AUTOcanbepassedasoneofthevalues.image.scale(f[,mode]);//scaletheimagebythefactorfimage.scaleToFit(w,h[,mode]);//scaletheimagetothelargestsizethatfitsinsidethegivenwidthandheight//Anoptionalresizemodecanbepassedwithallresizemethods./*Crop*/image.autocrop([tolerance,frames]);//automaticallycropsame-colorbordersfromimage(ifany),framesmustbeaBooleanimage.crop(x,y,w,h);//croptothegivenregion/*Flipandrotate*/image.flip(horz,vert);//fliptheimagehorizontallyorverticallyimage.mirror(horz,vert);//analiasforflipimage.rotate(deg[,mode]);//rotatetheimageclockwisebyanumberofdegrees.Optionally,aresizemodecanbepassed.If`false`ispassedasthesecondparameter,theimagewidthandheightwillnotberesized.image.exifRotate();//JPEGimageswithEXIForientationdatawillbeautomaticallyre-orientatedasappropriate.
[Jimp JavaScript 编写的图像处理库]相关推荐
MWT J2ME 的 UI 工具包

MWT J2ME 的 UI 工具包

Micro Window Toolkit(MWT)是一个用于开发J2ME用户界面(UI)的工具包。它具有友好,强大,快速,开源等特……...

Opus 音频解码器

Opus 音频解码器

Opus 是一个完全开源,免费的,通用性高的音频解码器。Opus 在网络上有着无与伦比的交互式语音和音乐传播……...

Seay

Seay

Seay 是一个PHP 代码审计工具。 软件界面: 本人目前就读重庆某软件学院软件测试专业,将于2013年1月底……...

pippo 微型 Java Web 框架

它是一个开源的微型Java Web框架,拥有最少的依赖,以及快速的学习曲线。 该项目的目标是创建一个微型的W……...

今日开源
  1. Eigen 线性算术的 C++ 模板库

    Eigen 是一个线性算术的C++模板库,包括:vectors, matrices, 以及相关算法。功能强大、快速、优雅以及支持多平台。 示例代码: #include <iostream>#include <Eigen/Dense>using namespace Eigen;int……

    开源软件 2024-05-10

  2. OSv 开源操作系统

    OSv 是专为在虚拟机上运行单一应用程序而设计的开源操作系统,采用BSD许可证授权,旨在在云端取代Linux。 与为大量物理机设计的传统操作系统相比,OSv是一种开放源代码的通用模块化Unikernel,旨在作为虚拟机在hyp……

    开源软件 2024-05-10

  3. Faust Python 流处理

    Faust 是一个流处理库,将想法从 Kafka Streams 移植到 Python。 它在 Robinhood 用于构建高性能的分布式系统和实时数据管道,每天处理数十亿个事件。 Faust 提供流处理和事件处理,与 Kafka Streams,Apache Spar……

    开源软件 2024-05-10

返回顶部小火箭