escpos-buffer
Advanced tools
Comparing version 4.0.1 to 4.0.2
@@ -0,1 +1,3 @@ | ||
import * as path from 'path'; | ||
import { ImageManager } from 'escpos-buffer-image'; | ||
import { load } from '../../helper'; | ||
@@ -5,6 +7,10 @@ import { BayerOrdered, Image } from '../../../src'; | ||
describe('proccess images using Bayer ordered algorithm', () => { | ||
it('apply filter on image from buffer', () => { | ||
const image = new Image(load('sample.png'), new BayerOrdered()); | ||
it('apply filter on image from buffer', async () => { | ||
const imageManager = new ImageManager(); | ||
const imageData = await imageManager.loadImage( | ||
path.join(__dirname, '../../resources/sample.png'), | ||
); | ||
const image = new Image(imageData, new BayerOrdered()); | ||
expect(image.data).toStrictEqual(load('bayer_filter', image.data)); | ||
}); | ||
}); |
@@ -0,1 +1,3 @@ | ||
import * as path from 'path'; | ||
import { ImageManager } from 'escpos-buffer-image'; | ||
import { load } from '../../helper'; | ||
@@ -5,4 +7,8 @@ import { FloydSteinberg, Image } from '../../../src'; | ||
describe('proccess images using Floyd and Steinberg algorithm', () => { | ||
it('apply filter on image from buffer', () => { | ||
const image = new Image(load('sample.png'), new FloydSteinberg()); | ||
it('apply filter on image from buffer', async () => { | ||
const imageManager = new ImageManager(); | ||
const imageData = await imageManager.loadImage( | ||
path.join(__dirname, '../../resources/sample.png'), | ||
); | ||
const image = new Image(imageData, new FloydSteinberg()); | ||
expect(image.data).toStrictEqual( | ||
@@ -9,0 +15,0 @@ load('floyd_steinberg_filter', image.data), |
@@ -0,1 +1,3 @@ | ||
import * as path from 'path'; | ||
import { ImageManager } from 'escpos-buffer-image'; | ||
import { load } from '../../helper'; | ||
@@ -5,6 +7,10 @@ import { Threshold, Image } from '../../../src'; | ||
describe('proccess images using threshold algorithm', () => { | ||
it('apply filter on image from buffer', () => { | ||
const image = new Image(load('sample.png'), new Threshold()); | ||
it('apply filter on image from buffer', async () => { | ||
const imageManager = new ImageManager(); | ||
const imageData = await imageManager.loadImage( | ||
path.join(__dirname, '../../resources/sample.png'), | ||
); | ||
const image = new Image(imageData, new Threshold()); | ||
expect(image.data).toStrictEqual(load('threshold_filter', image.data)); | ||
}); | ||
}); |
@@ -1,37 +0,29 @@ | ||
import { load } from '../helper'; | ||
import * as path from 'path'; | ||
import { ImageManager } from 'escpos-buffer-image'; | ||
import { Image } from '../../src'; | ||
import { PNG } from '../../src'; | ||
describe('proccess images to printing format', () => { | ||
it('load image from buffer', () => { | ||
const image = new Image(load('sample.png')); | ||
it('load image from buffer', async () => { | ||
const imageManager = new ImageManager(); | ||
const imageData = await imageManager.loadImage( | ||
path.join(__dirname, '../resources/sample.png'), | ||
); | ||
const image = new Image(imageData); | ||
expect(image.width).toBe(180); | ||
}); | ||
it('allow image cache', () => { | ||
const cache = new Image(load('sample.png')); | ||
const image = new Image(); | ||
it('allow image cache', async () => { | ||
const imageManager = new ImageManager(); | ||
const imageDataCache = await imageManager.loadImage( | ||
path.join(__dirname, '../resources/sample.png'), | ||
); | ||
const imageData = await imageManager.loadImage( | ||
path.join(__dirname, '../resources/transparent_sample.png'), | ||
); | ||
const cache = new Image(imageDataCache); | ||
const image = new Image(imageData); | ||
Object.assign(image, cache); | ||
expect(image.width).toBe(180); | ||
}); | ||
it('accepts a pre-loaded PNG instance', async () => { | ||
const imageBuffer = load('sample.png'); | ||
const png = await new Promise((resolve: Function, reject: Function) => { | ||
new PNG({ filterType: 4 }).parse( | ||
imageBuffer, | ||
(error: Error, data: PNG) => { | ||
if (error) { | ||
reject(error); | ||
return; | ||
} | ||
resolve(data); | ||
}, | ||
); | ||
}); | ||
const image = new Image(png as PNG); | ||
expect(image.width).toBe(180); | ||
}); | ||
}); |
import * as path from 'path'; | ||
import * as fs from 'fs'; | ||
import { ImageManager } from 'escpos-buffer-image'; | ||
import { Image } from '../src'; | ||
@@ -130,4 +132,12 @@ import { Capability } from '../src/capabilities'; | ||
const connection = new InMemory(); | ||
const printer = await Printer.CONNECT('MP-4200 TH', connection); | ||
const image = new Image(path.join(__dirname, 'resources/sample.png')); | ||
const imageManager = new ImageManager(); | ||
const printer = await Printer.CONNECT( | ||
'MP-4200 TH', | ||
connection, | ||
imageManager, | ||
); | ||
const imageData = await imageManager.loadImage( | ||
path.join(__dirname, 'resources/sample.png'), | ||
); | ||
const image = new Image(imageData); | ||
await printer.setAlignment(Align.Center); | ||
@@ -143,4 +153,14 @@ await printer.draw(image); | ||
const connection = new InMemory(); | ||
const printer = await Printer.CONNECT('MP-4200 TH', connection); | ||
const image = new Image(load('sample.png')); | ||
const imageManager = new ImageManager(); | ||
const printer = await Printer.CONNECT( | ||
'MP-4200 TH', | ||
connection, | ||
imageManager, | ||
); | ||
// tslint:disable: non-literal-fs-path | ||
const imageBuffer = fs.readFileSync( | ||
path.join(__dirname, 'resources/sample.png'), | ||
); | ||
const imageData = await imageManager.loadImageFromBuffer(imageBuffer); | ||
const image = new Image(imageData); | ||
await printer.setAlignment(Align.Center); | ||
@@ -147,0 +167,0 @@ await printer.draw(image); |
@@ -5,2 +5,3 @@ import InMemory from '../../src/connection/InMemory'; | ||
import { load } from '../helper'; | ||
import { ImageManager } from 'escpos-buffer-image'; | ||
@@ -46,5 +47,14 @@ describe('controlid model profile', () => { | ||
it('draw qrcode from model PrintiD without a image manager', async () => { | ||
const connection = new InMemory(); | ||
const printer = await Printer.CONNECT('PrintiD', connection); | ||
await expect( | ||
printer.qrcode('https://github.com/grandchef/escpos-buffer'), | ||
).rejects.toThrow('No image manager to draw qrcode'); | ||
}); | ||
it('draw qrcode from model PrintiD', async () => { | ||
const connection = new InMemory(); | ||
const printer = await Printer.CONNECT('PrintiD', connection); | ||
const imageManager = new ImageManager(); | ||
const printer = await Printer.CONNECT('PrintiD', connection, imageManager); | ||
await printer.setAlignment(Align.Center); | ||
@@ -60,3 +70,8 @@ await printer.qrcode('https://github.com/grandchef/escpos-buffer'); | ||
const connection = new InMemory(); | ||
const printer = await Printer.CONNECT('PrintiD-Touch', connection); | ||
const imageManager = new ImageManager(); | ||
const printer = await Printer.CONNECT( | ||
'PrintiD-Touch', | ||
connection, | ||
imageManager, | ||
); | ||
await printer.setAlignment(Align.Center); | ||
@@ -63,0 +78,0 @@ await printer.qrcode('https://github.com/grandchef/escpos-buffer'); |
@@ -0,1 +1,3 @@ | ||
import * as path from 'path'; | ||
import { ImageManager } from 'escpos-buffer-image'; | ||
import InMemory from '../../src/connection/InMemory'; | ||
@@ -52,4 +54,8 @@ import Printer from '../../src/Printer'; | ||
const connection = new InMemory(); | ||
const printer = await Printer.CONNECT('DR800', connection); | ||
const image = new Image(load('sample.png')); | ||
const imageManager = new ImageManager(); | ||
const printer = await Printer.CONNECT('DR800', connection, imageManager); | ||
const imageData = await imageManager.loadImage( | ||
path.join(__dirname, '../resources/sample.png'), | ||
); | ||
const image = new Image(imageData); | ||
await printer.setAlignment(Align.Center); | ||
@@ -56,0 +62,0 @@ await printer.draw(image); |
@@ -5,2 +5,3 @@ import InMemory from '../../src/connection/InMemory'; | ||
import { load } from '../helper'; | ||
import { ImageManager } from 'escpos-buffer-image'; | ||
@@ -43,5 +44,14 @@ describe('generic model profile', () => { | ||
it('draw qrcode from model CMP-20 without a image manager', async () => { | ||
const connection = new InMemory(); | ||
const printer = await Printer.CONNECT('CMP-20', connection); | ||
await expect( | ||
printer.qrcode('https://github.com/grandchef/escpos-buffer'), | ||
).rejects.toThrow('No image manager to draw qrcode'); | ||
}); | ||
it('draw qrcode from model CMP-20', async () => { | ||
const connection = new InMemory(); | ||
const printer = await Printer.CONNECT('CMP-20', connection); | ||
const imageManager = new ImageManager(); | ||
const printer = await Printer.CONNECT('CMP-20', connection, imageManager); | ||
await printer.setAlignment(Align.Center); | ||
@@ -48,0 +58,0 @@ await printer.qrcode('https://github.com/grandchef/escpos-buffer'); |
{ | ||
"name": "escpos-buffer", | ||
"version": "4.0.1", | ||
"version": "4.0.2", | ||
"description": "Library to generate buffer for thermal printers.", | ||
@@ -39,2 +39,3 @@ "author": "GrandChef Team <desenvolvimento@grandchef.com.br>", | ||
"@types/web-bluetooth": "^0.0.16", | ||
"escpos-buffer-image": "^1.1.0", | ||
"jest": "^29.4.1", | ||
@@ -41,0 +42,0 @@ "prettier": "^2.8.3", |
411082
207
5477
14