Possible, but a non-obvious. You’ll need to use Document#save to export the document as a PNG or JPEG. This means you’ll need to do some work that extracts the layer you wish to export to create a new temporary document that can then be used to save the rendition. Better APIs are planned for this year, but for now, the process is a bit awkward.
Upload the layer information
You can get the layer’s name using the Layer#name. This can be uploaded using fetch, XMLHttpRequest or WebSocket.
Convert the user’s layer into a picture, and then upload (sliced images)
May need more context here, but getting a rendition here would be similar to uploading the screenshot of the artboard.
Getting slice information will require batchPlay. You’ll want to use Jarda’s excellent Alchemist plugin to discover how this works as what you can do with batchPlay is not otherwise well documented.
Better APIs are planned for this year, but for now, the process is a bit awkward.
How is this going?
Our goal is to get the slice PNG/SVG/JPG buffer of the layer (if needed, @1x,@2x,etc. ), and upload to our service. like Zeplin Plugin.
Currently I can only do this:
create temp Document
copy layer to this Document (and hide some auxiliary child layers.)
scale layer if needed. Extra, scale strokes, radius and effects by batchPlay
create temp local file
save document to temp file
read buffer from local file
close temp document (can not reuse it, because document can not clear all layers easily)
repeat 1 to handle next layer
This leads to unsatisfactory performance.
We are eager for a simpler and better-performing way to finish this job.Just like const buffer = layer.getLayerBuffer({type:'png', scale: 2, ...otherOptions})
Or is there a better way I haven’t found?