Path: blob/master/node_modules/@jimp/png/test/png.test.js
1126 views
import { Jimp, getTestDir } from '@jimp/test-utils';1import configure from '@jimp/custom';23import png from '../src';45const jimp = configure({ types: [png] }, Jimp);67describe('PNG', () => {8const imagesDir = getTestDir(__dirname) + '/images';910it('load PNG', async () => {11const image = await jimp.read(imagesDir + '/dice.png');1213image.getPixelColor(10, 10).should.be.equal(0x00000000);14image.getPixelColor(160, 80).should.be.equal(0x1c1cd4ff);15image.getPixelColor(400, 250).should.be.equal(0x7e0c0cda);16});1718it('export PNG', async () => {19const jgd = await jimp.read({20width: 3,21height: 3,22data: [230xff0000ff,240xff0080ff,250xff00ffff,260xff0080ff,270xff00ffff,280x8000ffff,290xff00ffff,300x8000ffff,310x0000ffff32]33});34const buffer = await jgd.getBufferAsync('image/png');3536buffer.toString().should.match(/^.PNG\r\n/);37});3839it('should use png options', async () => {40const jgd = await jimp.read({41width: 20,42height: 20,43data: [440xff0000ff,450xff0080ff,460xff00ffff,470xff0080ff,480xff00ffff,490x8000ffff,500xff00ffff,510x8000ffff,520x0000ffff,530xff0000ff,540xff0080ff,550xff00ffff,560xff0080ff,570xff00ffff,580x8000ffff,590xff00ffff,600x8000ffff,610x0000ffff,620xff0000ff,630xff0080ff,640xff00ffff,650xff0080ff,660xff00ffff,670x8000ffff,680xff00ffff,690x8000ffff,700x0000ffff,710xff0000ff,720xff0080ff,730xff00ffff,740xff0080ff,750xff00ffff,760x8000ffff,770xff00ffff,780x8000ffff,790x0000ffff80]81});8283const image = await jgd84.deflateStrategy(0)85.colorType(0)86.getBufferAsync(Jimp.MIME_PNG);8788const expected = await jimp.read(imagesDir + '/options.png');89const expectedBuffer = await expected90.deflateStrategy(0)91.colorType(0)92.getBufferAsync(Jimp.MIME_PNG);9394image.should.be.deepEqual(expectedBuffer);95});96});979899