import { OpenSheetMusicDisplay , CanvasVexFlowBackend } from "../../src" ; import { TestUtils } from "./TestUtils" ; describe ( "GeneratePNGImages" , ( ) => { const sampleFilenames = [ "Beethoven_AnDieFerneGeliebte.xml" , "MuzioClementi_SonatinaOpus36No1_Part1.xml" , ] ; for ( const score of sampleFilenames ) { generatePNG ( score ) ; } function generatePNG ( sampleFilename ) { it ( sampleFilename , ( done ) => { const score = TestUtils . getScore ( sampleFilename ) ; const div = document . createElement ( "div" ) ; const openSheetMusicDisplay = new OpenSheetMusicDisplay ( div , { autoResize : false , backend : "canvas" } ) ; openSheetMusicDisplay . load ( score ) ; const testDir = "../data/images" ; const fileName = `${ testDir }/${ sampleFilename }.png` ; console . log ( "fileName: " + fileName ) ; console . log ( "before buffer" ) ; const canvasBackend = openSheetMusicDisplay . Drawer . Backends [ 0 ] as CanvasVexFlowBackend ; const imageData = ( canvasBackend . getCanvas ( ) as HTMLCanvasElement ) . toDataURL ( ) . split ( ";base64," ) . pop ( ) ; const imageBuffer = Buffer . from ( imageData , "base64" ) ; console . log ( "imageBuffer.length: " + imageBuffer . length ) ; done ( ) ; } ) . timeout ( 30000 ) ; } } ) ;