一个简单的图片解码玩具
constPng=require('doimg').Png;letpng=newPng(buffer);console.log(png.width);// 图像宽度console.log(png.height);// 图像高度console.log(png.bitDepth);// 图像深度,即每个通道包含的位数console.log(png.colorType);// 颜色类型,0 - 灰度,2 - rgb,3 - 索引,4 - 灰度+aloha,6 - rgbaconsole.log(png.alpha);// 是否使用alpha通道letpixels=png.decode();// 像素数据constGif=require('doimg').Gif;letgif=newGif(buffer);console.log(gif.width);// 图像宽度console.log(gif.height);// 图像高度console.log(gif.bitDepth);// 图像深度console.log(gif.backgroundColorIndex);// 背景颜色letimages=png.decode();// 图片列表像素数据letfirstImg=images[0];// 取图片列表中第一张console.log(firstImg.left);// 图像左边偏移console.log(firstImg.top);// 图像上边偏移console.log(firstImg.width);// 图像宽度console.log(firstImg.height);// 图像高度console.log(firstImg.disposalMethod);// 处置方法,0 - 不使用处置方法,1 - 不处置图形,把图形从当前位置移去,2 - 回复到背景色,3 - 回复到先前状态console.log(firstImg.userInputFlag);// 用户输入标志,指出是否期待用户有输入之后才继续进行下去,0 - 不期待,1 - 期待console.log(firstImg.delayTime);// 延迟时间,单位1/100秒constJpeg=require('doimg').Jpeg;letjpeg=newJpeg(buffer);console.log(jpeg.width);// 图像宽度console.log(jpeg.height);// 图像高度console.log(jpeg.thumbnailWidth);// 缩略图宽度console.log(jpeg.thumbnailHeight);// 缩略图高度console.log(jpeg.thumbnail);// 缩略图数据letpixels=jpeg.decode();// 像素数据MIT