0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-22 21:53:27 -05:00
penpot-exporter-figma-plugin/plugin-src/transformers/transformImageNode.ts
2024-04-12 18:52:19 +02:00

30 lines
705 B
TypeScript

import { detectMimeType } from '@plugin/utils';
import { ImageShape } from '@ui/lib/types/image/imageShape';
export const transformImageNode = async (
node: SceneNode,
baseX: number,
baseY: number
): Promise<ImageShape> => {
let dataUri = '';
if ('exportAsync' in node) {
const value = await node.exportAsync({ format: 'PNG' });
const b64 = figma.base64Encode(value);
dataUri = 'data:' + detectMimeType(b64) + ';base64,' + b64;
}
return {
type: 'image',
name: node.name,
x: node.x + baseX,
y: node.y + baseY,
width: node.width,
height: node.height,
metadata: {
width: node.width,
height: node.height
},
dataUri: dataUri
};
};