pngjs-image中文文档|pngjs-image js中文教程|解析
安装命令:npm i pngjs-image
PNGjs-图片
基于 JavaScript 的 PNG 图像编码器、解码器和操作器
目录
安装
使用以下命令安装此模块:
npm install pngjs-image
将模块添加到您的package.json
依赖项中:
npm install --save pngjs-image
将模块添加到您的package.json
开发依赖项:
npm install --save-dev pngjs-image
在源代码中需要模块:
var PNGImage = ;
用法
示例:创建新图像
var image = PNGImage; // Get width and heightconsole;console; // Set a pixel at (20, 30) with red, having an alpha value of 100 (half-transparent)image; // Get index of coordinate in the image buffervar index = image; // Print the red color valueconsole; // Get low level image object with buffer from the 'pngjs' packagevar pngjs = image; image;
示例:加载图像
PNGImage;
示例:从 url 加载图像
PNGImage;
静态方法
<PNGImage> = PNGImage.addFilter(key, fn)
将fn
带有标识符key
的过滤器添加到过滤器列表中<PNGImage> = PNGImage.createImage(width, height)
创建具有给定大小的图像<PNGImage> = PNGImage.copyImage(image)
将图像复制到新容器中PNGImage.readImage(path, fn)
从文件或 url 加载图像,fn
完成后调用该函数PNGImage.loadImage(blob, fn)
从内存加载图像,fn
完成后调用该函数
实例方法
<pngjs> = image.getImage()
获取pngjs
实例<Buffer> = image.getBlob()
获取数据作为缓冲对象<int> = image.getWidth()
获取图像的宽度<int> = image.getHeight()
获取图像的高度image.clip(x, y, width, height)
剪辑当前图像;尺寸必须小于原始图像image.fillRect(x, y, width, height, color)
用提供的颜色填充矩形image.applyFilters(filters, returnResult)
将过滤器列表应用于图像<int> = image.getIndex(x, y)
将 x 和 y 坐标转换为图像缓冲区的顺序索引image.writeImage(path, fn)
将图像写入文件系统并fn
在完成后调用该函数image.toBlob(fn)
将数据导出到缓冲区并fn
在完成后调用该函数
像素操作
<uint32> = image.getAtIndex(idx)
在索引处获取完整的 32 位像素idx
<uint32> = image.getAt(x, y)
在 x 和 y 坐标处获取完整的 32 位像素<uint32> = image.getPixel(x, y)
在 x 和 y 坐标处获取完整的 32 位像素image.setAtIndex(idx, color)
在索引处设置特定颜色。保留的颜色不会被修改。image.setAt(x, y, color)
在 x 和 y 坐标处设置特定颜色。保留的颜色不会被修改。image.setPixel(x, y, color)
在 x 和 y 坐标处设置特定颜色。保留的颜色不会被修改。<uint32> = image.getColorAtIndex(idx)
获取索引处像素的颜色分量idx
<uint32> = image.getColor(x, y)
获取像素在 x 和 y 坐标处的颜色分量<uint8> = image.getRed(idx)
获取某个索引处的红色强度image.setRed(idx, value, opacity)
在索引处设置红色强度<uint8> = image.getGreen(idx)
获取某个索引处的绿色强度image.setGreen(idx, value, opacity)
在索引处设置绿色强度<uint8> = image.getBlue(idx)
获取某个索引处的蓝色强度image.setBlue(idx, value, opacity)
在索引处设置蓝色强度<uint8> = image.getAlpha(idx)
获取索引处的 alpha 强度image.setAlpha(idx, value, opacity)
在索引处设置 alpha 强度
像素转换
<uint32> = image.getBlurPixelAt(idx, funcName)
获取索引处像素的模糊颜色idx
<uint32> = image.getYIQAtIndex(idx)
获取索引处像素的 YIQ 值idx
<uint32> = image.getYIQ(x, y)
获取像素在 x 和 y 坐标处的 YIQ 值<uint32> = image.getLumaAtIndex(idx)
获取索引处像素的亮度idx
<uint32> = image.getLuma(x, y)
获取像素在 x 和 y 坐标处的亮度<uint32> = image.getSepiaAtIndex(idx)
获取索引处像素的棕褐色idx
<uint32> = image.getSepia(x, y)
获取像素在 x 和 y 坐标处的棕褐色<uint32> = image.getLuminosityAtIndex(idx)
获取索引处像素的亮度idx
<uint32> = image.getLuminosity(x, y)
获取像素在 x 和 y 坐标处的亮度<uint32> = image.getLightnessAtIndex(idx)
获取索引处像素的亮度idx
<uint32> = image.getLightness(x, y)
获取像素在 x 和 y 坐标处的亮度<uint32> = image.getGrayScaleAtIndex(idx)
获取索引处像素的灰度值idx
<uint32> = image.getGrayScale(x, y)
获取像素在 x 和 y 坐标处的灰度值
过滤器
以下过滤器可以应用于图像:
- 模糊
- 灰度
- 亮度
- 亮度
- 亮度
- 棕褐色
API-文档
使用以下命令生成文档:
npm run docs
文档将docs
在模块根目录的文件夹中生成。
测试
使用以下命令运行测试:
npm run test
代码覆盖将写入coverage
模块根目录中的文件夹。
第三方库
此模块使用以下第三方库:
依赖关系
- pako:https : //github.com/nodeca/pako
- pngjs: https://github.com/niegowski/node-pngjs
- 流缓冲区:https : //github.com/samcday/node-stream-buffer
- 下划线:http : //underscorejs.org
- 请求:https : //github.com/request/request
开发依赖
- 柴:http : //chaijs.com
- 工作服:https : //github.com/cainus/node-coveralls
- codeclimate-test-reporter: https://github.com/codeclimate/javascript-test-reporter
- 伊斯坦布尔:https : //github.com/gotwarlost/istanbul
- 摩卡咖啡:https : //github.com/visionmedia/mocha
- sinon:http ://sinonjs.org
- sinon-chai: https://github.com/domenic/sinon-chai
- yuidocjs:https : //github.com/yui/yuidoc
执照
麻省理工学院执照
版权所有 2014-2015 雅虎公司。
项目issue地址: https://github.com/yahoo/pngjs-image/issues
项目issue数量: 3
项目贡献人员列表: