Skip to main content
Vincent_Huss
Active Member
Nov 5, 2024 4:13 AM UTC
Question

Detect if fill image has transparency or not

Hi !

I would like to be able to detect wether a fill of type image contains transparency or not.

I’m developping a code exporter and there are multiple reason why this information would be useful, for example :

  • knowing wether its more relevant to export as PNG or JPG (without having to ask the user)

  • knowing wether a shadow effect applied to that image should rather be handled in CSS (in the case of a jpg without transparency) or should be integrated in the export (in the case of a png with transparency)

please let me know if there’s any way to know this, (even a work-around)

Best regards.

This topic has been closed for replies.

3 replies

tank666
Nov 5, 2024 6:17 PM UTC

Get the image fill byte array and analyze the data signature to match the file formats.

figma.com
UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank
Vincent_Huss
Active Member
Nov 6, 2024 1:54 AM UTC

Thanks for all the resources, this sounds like a reliable solution,
And is there any other way to do it before the async call to Image.getBytesAsync ?

Cheers

tank666
Nov 6, 2024 5:40 AM UTC

No, there are no other ways to get the image format without getting its bytes.

UX/UI designer. Figma expert. Creator and developer of plugins and widgets for Figma and FigJam. Check out my resources in Figma Community: figma.com/@tank