Skip to main content
Question

Detect if fill image has transparency or not

  • November 5, 2024
  • 3 replies
  • 63 views

Vincent_Huss

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
  • 4873 replies
  • November 5, 2024

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

figma.com

Vincent_Huss
  • Author
  • Active Member
  • 29 replies
  • November 6, 2024

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
  • 4873 replies
  • November 6, 2024

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