yuanqing / figma-plugins

:fire: Monorepo for my Figma plugins
https://figma.com/@yuanqing
MIT License
239 stars 32 forks source link

Flatten Selection to Bitmap: Image is too large #19

Closed davo closed 3 years ago

davo commented 4 years ago

Figma won't raster when the scale multiplier results in widths / heights over 4096.2.

Flatten @ 3x with a frame @ 1365x1365

Screen Shot 2020-09-15 at 5 02 26 PM

Flatten @ 3x with a frame @ 1366x1366

Screen Shot 2020-09-15 at 5 02 40 PM
davo commented 3 years ago

Hey @yuanqing will it help to talk about some potential solutions for this bug? I want to take a stab at the issue but I'd like your opinion about which direction seems more feasible.

First, from what I gather Figma states the limits of the createImage method regarding image max size. They are following a common best practice for universal supported limits, in which textures using texImage2D should not go over 4096. Source: MDN WebGL best practices.

Here are some potential scenarios:

Here are are the rasters from the the GET image endpoint.

File / Scale 2x 3x 4x
1024 Image Image Image
2048 Image Image Image

Figma API Docs for reference:

Screen Shot 2021-04-02 at 3 29 37 PM

PNG downloaded from the Endpoint

Screen Shot 2021-04-02 at 3 30 51 PM
yuanqing commented 3 years ago

@davo

raster a node with the API, and right after insert that blob back to the canvas using the methods you created on Insert Big Image

Thanks for the detailed write-up! I quickly looked into this today and it turned out to be a small change because most of the implementation is already done in Insert Big Image – d474401

yuanqing commented 3 years ago

Just published a new version of the plugin to Figma. It’ll take some time to run if you have a large selection or when flattening at a high resolution

davo commented 3 years ago

Thanks @yuanqing! I'm glad it the write-up helped in any way.

Amazed by the PR with 63 additions and 69 deletions, and the fact that you are achieving this level of reusability between your own work 👏🏼