Ps plugin abilities

hello experts
One question from customer, Currently they are working on a PS plug-in and the functions are similar with XD plugin.

  1. Upload a screenshot of the art board,
  2. Upload the layer information (label)
  3. Convert the user’s layer into a picture, and then upload (sliced images)

They want to know how they can achieve these abilities, thank you for your help

1 Like
  1. Upload a screenshot of the artboard

    • 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.
  2. Upload the layer information

    • You can get the layer’s name using the Layer#name. This can be uploaded using fetch, XMLHttpRequest or WebSocket.
  3. 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.

Hello @kerrishotts

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:

  1. create temp Document
  2. copy layer to this Document (and hide some auxiliary child layers.)
  3. scale layer if needed. Extra, scale strokes, radius and effects by batchPlay
  4. create temp local file
  5. save document to temp file
  6. read buffer from local file
  7. close temp document (can not reuse it, because document can not clear all layers easily)
  8. 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?

I did some tests, and I think the slower problem mainly appeared on some dom APIs.

For a layer with 26 sub-layers:

  • took 1.78s to copy to the temp document, use Layer#duplicate
  • took 2.33s to adjust the layer position(It’s not always center of the document after scale the layer), use Layer#nudge
  • took 800ms to scale effect,stroke width and radius. not dom API, use batchPlay for each one

At least on my computer, and it makes me very frustrated.