I wish to export a particular layer from my figma file. I refer this link. https://www.figma.com/developers/api#get-file-nodes-endpoint
But when I try to run the cURL command, I am getting the entire screen. For example, if the screen size is 1920x1080, and if I try to export an image of size 100x100, it is still returning an image URL of 1920x1080
Basically can we give a particular layer item instead of 525%3A4832&t=jDeGTNemBZ14AaSq-0? When I change different layer items, 525%3A4832&t=jDeGTNemBZ14AaSq-0 is not changing in the URL. it is the nodeId
Thank you Gleb for your time and kind reply. But could I ask,
scale will set the image size only right?
Also, can we mention X,Y,Width and Height to export exactly a specific node item in the layer? Or my understanding about node is different?
If you want to export an image at a specific width or height, you need to mathematically calculate the scale you need to set based on the current width/height of the node and the desired one. scale = exportWidth / currentWidth
Every node has a unique ID. GET images endpoint allows you to render a specific node. So to render the blue rectangle, you need to pass its ID into the GET images endpoint in the ids array as instructed in the docs.
The ID in the URL will not change because the URL only reflects the ID of the top-level frame where you have something selected. To find the exact ID of an object, you either need to use the plugins API (figma.currentPage.selection[0].id) or find this object via the REST API by some known properties (such as name, position, etc.) after getting the whole file via GET file endpoint.
OK. So if I write a new plugin, can I include this cURL in the typescript plugin? I am trying to iterate through the scenegraph, export each layer image I want. I saw some figma plugins but it didn’t work. So I am switching to cUrl way
You don’t need to use REST API if you are already using plugins API and only need to export certain nodes. You can export nodes as images via plugins API. But I don’t have an example of that.
If necessary, you can also use REST API within the plugin by using fetch if you only build it for yourself and plan to use it privately.
Yeah, just for this purpose, I learned how to write plugins for figma. Started with the youtube tutorials, and tried to run some github based examples. I know how to iterate through the document, hide layers show layers etc.
node.exportAsyncexportAsync | Plugin API will get you the image data. But I don’t know how to save it to the computer, I haven’t done that myself yet. Try finding some examples on github. Sorry I can’t help any further.