1
1
import { Upscaler } from "upscalejs"
2
- import "jimp"
3
- // eslint-disable-next-line
4
- const { Jimp } = window as any
2
+ import { Jimp } from "jimp" ;
3
+
4
+ const MIME_PNG = "image/png"
5
5
6
6
const resizeBitmap = async ( bitmap : ImageBitmap , targetSize : number ) : Promise < Blob > => {
7
7
const canvas = document . createElement ( "canvas" )
@@ -12,12 +12,14 @@ const resizeBitmap = async (bitmap: ImageBitmap, targetSize: number): Promise<Bl
12
12
13
13
ctx . drawImage ( bitmap , 0 , 0 ) ;
14
14
const imageData = ctx . getImageData ( 0 , 0 , canvas . width , canvas . height ) ;
15
- const image = await Jimp . read ( imageData ) ;
15
+ const image = await Jimp . fromBitmap ( imageData ) ;
16
16
17
- image . resize ( parseInt ( `${ targetSize } ` ) , parseInt ( `${ targetSize } ` ) ) ;
18
- const resizedBuffer = await image . getBufferAsync ( Jimp . MIME_PNG ) ;
17
+ const target = parseInt ( `${ targetSize } ` )
18
+ const resized = await image
19
+ . resize ( { w : target , h : target } )
20
+ . getBuffer ( MIME_PNG )
19
21
20
- return new Blob ( [ resizedBuffer ] , { type : Jimp . MIME_PNG } ) ;
22
+ return new Blob ( [ resized ] , { type : MIME_PNG } ) ;
21
23
}
22
24
23
25
export const scaleImage = async ( bitmap : ImageBitmap , targetSize : number , workerPool : Upscaler ) : Promise < ImageBitmap > => {
0 commit comments