@pixi/utils
Version:
Collection of utilities used by PixiJS
1 lines • 1.58 kB
Source Map (JSON)
{"version":3,"file":"trimCanvas.mjs","sources":["../../src/media/trimCanvas.ts"],"sourcesContent":["import { getCanvasBoundingBox } from './getCanvasBoundingBox';\n\nimport type { ICanvas } from '@pixi/settings';\n\n/**\n * Trim transparent borders from a canvas.\n * @memberof PIXI.utils\n * @param {PIXI.ICanvas} canvas - The canvas to trim.\n * @returns The trimmed canvas data.\n */\nexport function trimCanvas(canvas: ICanvas): { width: number, height: number, data: ImageData | null }\n{\n const boundingBox = getCanvasBoundingBox(canvas);\n const { width, height } = boundingBox;\n let data = null;\n\n if (!boundingBox.isEmpty())\n {\n const context = canvas.getContext('2d');\n\n if (context === null)\n {\n throw new TypeError('Failed to get canvas 2D context');\n }\n\n data = context.getImageData(\n boundingBox.left,\n boundingBox.top,\n width,\n height\n );\n }\n\n return { width, height, data };\n}\n"],"names":[],"mappings":";;AAUO,SAAA,UAAA,CAAoB,MAC3B,EAAA;AACI,EAAM,MAAA,WAAA,GAAc,qBAAqB,MAAM,CAAA,CAAA;AAC/C,EAAM,MAAA,EAAE,OAAO,MAAW,EAAA,GAAA,WAAA,CAAA;AAC1B,EAAA,IAAI,IAAO,GAAA,IAAA,CAAA;AAEX,EAAI,IAAA,CAAC,WAAY,CAAA,OAAA,EACjB,EAAA;AACI,IAAM,MAAA,OAAA,GAAU,MAAO,CAAA,UAAA,CAAW,IAAI,CAAA,CAAA;AAEtC,IAAA,IAAI,YAAY,IAChB,EAAA;AACI,MAAM,MAAA,IAAI,UAAU,iCAAiC,CAAA,CAAA;AAAA,KACzD;AAEA,IAAA,IAAA,GAAO,QAAQ,YACX,CAAA,WAAA,CAAY,MACZ,WAAY,CAAA,GAAA,EACZ,OACA,MACJ,CAAA,CAAA;AAAA,GACJ;AAEA,EAAO,OAAA,EAAE,KAAO,EAAA,MAAA,EAAQ,IAAK,EAAA,CAAA;AACjC;;;;"}