{"ScriptPreparationCode":"// const sourceImage = new Image();\r\nconst sourceImage = document.querySelector(\u0027#source\u0027);\r\nconst imageLoaded = new Promise((resolve, reject) =\u003E {\r\n if (sourceImage.complete) resolve(sourceImage);\r\n sourceImage.onload = () =\u003E resolve(sourceImage);\r\n sourceImage.onerror = reject;\r\n // resolve(source1);\r\n});\r\n\r\nconst imageBlobLoaded = fetch(\u0027https://placekitten.com/1280/720\u0027).then(res =\u003E res.blob())\r\n\r\nfunction scaleSource(sw, sh, dw, dh) {\r\n const hRatio = dw / sw;\r\n const vRatio = dh / sh;\r\n const ratio = Math.max(hRatio, vRatio);\r\n const x = (sw - dw / ratio) / 2;\r\n const y = (sh - dh / ratio) / 2;\r\n return { x, y, w: sw - x * 2, h: sh - y * 2, ratio };\r\n}\r\n\r\nconst profileWidth = 480;\r\nconst profileHeight = 360;\r\n\r\n// Remember, all the outputs must be an ImageBitmap to be a fair comparison\r\n\r\n// case 1: use createImageBitmap to crop and resize, bugged in firefox but working in Chrome\r\nasync function case1_createImageBitmapWithImg() {\r\n const source = await imageLoaded;\r\n const bitmap = await window.createImageBitmap(\r\n source,\r\n source.width,\r\n source.height,\r\n 0,\r\n 0\r\n );\r\n\r\n return bitmap;\r\n}\r\n\r\n// case 2: use canvas to crop and resize\r\nasync function case2_createImageBitmapWithBlob() {\r\n const source = await imageBlobLoaded;\r\n const bitmap = await window.createImageBitmap(\r\n source,\r\n source.width,\r\n source.height,\r\n 0,\r\n 0\r\n );\r\n\r\n return bitmap;\r\n}","TestCases":[{"Name":"Create ImageBitmap with Img element","Code":"case1_createImageBitmapWithImg()\r\n\t.then(bitmap =\u003E bitmap.close());","IsDeferred":false},{"Name":"Create ImageBitmap with Blob","Code":"case2_createImageBitmapWithBlob()\r\n\t.then(bitmap =\u003E bitmap.close());","IsDeferred":false}]}