0
Fork 0
mirror of https://github.com/penpot/penpot-exporter-figma-plugin.git synced 2024-12-23 06:04:01 -05:00
penpot-exporter-figma-plugin/plugin-src/translators/fills/translateImageFill.ts
Jordi Sala Morales 3094f05e98
Optimize images before generating zip file (#141)
* Optimize images before generating zip file

* add changelog

* refactor

* fix lint
2024-06-05 12:36:49 +02:00

26 lines
688 B
TypeScript

import { imagesLibrary } from '@plugin/ImageLibrary';
import { Fill } from '@ui/lib/types/utils/fill';
import { PartialImageColor } from '@ui/lib/types/utils/imageColor';
export const translateImageFill = (fill: ImagePaint): Fill | undefined => {
const fillImage = translateImage(fill.imageHash);
if (!fillImage) return;
return {
fillOpacity: !fill.visible ? 0 : fill.opacity,
fillImage
};
};
const translateImage = (imageHash: string | null): PartialImageColor | undefined => {
if (!imageHash) return;
if (imagesLibrary.get(imageHash) === undefined) {
imagesLibrary.register(imageHash, figma.getImageByHash(imageHash));
}
return {
imageHash
};
};