mirror of
https://github.com/penpot/penpot-exporter-figma-plugin.git
synced 2024-12-22 21:53:27 -05:00
28 lines
749 B
TypeScript
28 lines
749 B
TypeScript
import { transformDimensionAndPosition } from '@plugin/transformers/partials';
|
|
import { detectMimeType } from '@plugin/utils';
|
|
|
|
import { ImageShape } from '@ui/lib/types/shapes/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)
|
|
};
|
|
};
|