11import * as path from 'path' ;
2+ import * as fs from 'fs' ;
3+ import { ImageManager } from 'escpos-buffer-image' ;
24import { Image } from '../src' ;
35import { Capability } from '../src/capabilities' ;
46import InMemory from '../src/connection/InMemory' ;
@@ -127,8 +129,16 @@ describe('print formatted text', () => {
127129
128130 it ( 'draw picture from file' , async ( ) => {
129131 const connection = new InMemory ( ) ;
130- const printer = await Printer . CONNECT ( 'MP-4200 TH' , connection ) ;
131- const image = new Image ( path . join ( __dirname , 'resources/sample.png' ) ) ;
132+ const imageManager = new ImageManager ( ) ;
133+ const printer = await Printer . CONNECT (
134+ 'MP-4200 TH' ,
135+ connection ,
136+ imageManager ,
137+ ) ;
138+ const imageData = await imageManager . loadImage (
139+ path . join ( __dirname , 'resources/sample.png' ) ,
140+ ) ;
141+ const image = new Image ( imageData ) ;
132142 await printer . setAlignment ( Align . Center ) ;
133143 await printer . draw ( image ) ;
134144 await printer . setAlignment ( Align . Left ) ;
@@ -139,8 +149,18 @@ describe('print formatted text', () => {
139149
140150 it ( 'draw picture from buffer' , async ( ) => {
141151 const connection = new InMemory ( ) ;
142- const printer = await Printer . CONNECT ( 'MP-4200 TH' , connection ) ;
143- const image = new Image ( load ( 'sample.png' ) ) ;
152+ const imageManager = new ImageManager ( ) ;
153+ const printer = await Printer . CONNECT (
154+ 'MP-4200 TH' ,
155+ connection ,
156+ imageManager ,
157+ ) ;
158+ // tslint:disable: non-literal-fs-path
159+ const imageBuffer = fs . readFileSync (
160+ path . join ( __dirname , 'resources/sample.png' ) ,
161+ ) ;
162+ const imageData = await imageManager . loadImageFromBuffer ( imageBuffer ) ;
163+ const image = new Image ( imageData ) ;
144164 await printer . setAlignment ( Align . Center ) ;
145165 await printer . draw ( image ) ;
146166 await printer . setAlignment ( Align . Left ) ;
0 commit comments