0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2025-01-05 06:10:52 -05:00
penpot-exporter-figma-plugin/plugin-src/transformers/transformImageNode.ts

29 lines
748 B
TypeScript
Raw Normal View History

2024-04-15 06:58:51 -05:00
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
},
2024-04-15 06:58:51 -05:00
dataUri: dataUri,
...transformDimensionAndPosition(node, baseX, baseY)
};
};