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-15 11:58:51 +00:00

28 lines
748 B
TypeScript

import { transformDimensionAndPosition } from '@plugin/transformers/partials';
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,
metadata: {
width: node.width,
height: node.height
},
dataUri: dataUri,
...transformDimensionAndPosition(node, baseX, baseY)
};
};