@@ -186,13 +186,13 @@ function convertBuffer(buffer, bits, bitsString = false)
186186
187187async function convertImage ( path )
188188{
189- const webpPath = fileManager . realPath ( path ) ;
189+ const pngPath = fileManager . realPath ( path ) ;
190190 const realPath = fileManager . realPath ( path , - 1 ) ;
191191
192- fileManager . setTmpUsage ( webpPath ) ;
192+ fileManager . setTmpUsage ( pngPath ) ;
193193
194- if ( fs . existsSync ( webpPath ) )
195- return webpPath ;
194+ if ( fs . existsSync ( pngPath ) )
195+ return pngPath ;
196196
197197 const result = await work ( {
198198 job : 'convertImage' ,
@@ -201,30 +201,38 @@ async function convertImage(path)
201201 mime : mime . getType ( realPath ) ,
202202 } ) ;
203203
204- if ( result . buffer )
205- {
206- const parentPath = p . dirname ( webpPath ) ;
204+ const parentPath = p . dirname ( pngPath ) ;
207205
208- if ( ! fs . existsSync ( parentPath ) )
209- fs . mkdirSync ( parentPath ) ;
206+ if ( ! fs . existsSync ( parentPath ) )
207+ fs . mkdirSync ( parentPath ) ;
210208
209+ if ( result . buffer )
210+ {
211211 const bits = result . bits ;
212212
213213 if ( bits > 8 && result . buffer instanceof Uint8Array )
214214 result . buffer = convertBuffer ( result . buffer , bits , result . bitsString ) ;
215215
216- await image . rawToPng ( result . buffer , webpPath , {
216+ const raw = {
217217 width : result . width ,
218218 height : result . height ,
219219 channels : result . channels ,
220220 rgb16 : bits > 8 ? true : false ,
221221 premultiplied : result . premultiplied || false ,
222- } , {
222+ } ;
223+
224+ await image . rawToPng ( result . buffer , pngPath , raw , {
223225 compressionLevel : 2 ,
224226 removeAlpha : result . removeAlpha ,
225227 } ) ;
226228
227- return webpPath ;
229+ return pngPath ;
230+ }
231+ else if ( result . png && result . png instanceof Uint8Array )
232+ {
233+ fs . writeFileSync ( pngPath , Buffer . from ( result . png ) , function ( ) { } ) ;
234+
235+ return pngPath ;
228236 }
229237
230238 if ( result . error )
0 commit comments