• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

How to save layers with cropping?

New Here ,
Dec 04, 2013 Dec 04, 2013

Copy link to clipboard

Copied

I want to export layers to files (basically what "Export Layers To Files.jsx" does) but with cropping each layer (to different sizes). I know how to crop a document from script, but that also crops all other layers (erases their content outside of the cropping area). So my question is - how do I keep/retrieve the cropped out content of the document (layers)? Or maybe there's a better approach altogether?

TOPICS
Actions and scripting

Views

1.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Community Expert ,
Dec 04, 2013 Dec 04, 2013

Copy link to clipboard

Copied

There's only one crop availble per document.  The only other option would be a layer mask.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 04, 2013 Dec 04, 2013

Copy link to clipboard

Copied

Layer masks hide pixels but I need the exported images to be cropped (different size).

So my only option is to copy the layer, create a new document, crop it, save it and then return to the original document? I'm afraid that will take forever for bigger documents.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 04, 2013 Dec 04, 2013

Copy link to clipboard

Copied

Well, it might be a roundabout way of getting what you want, but if you use the layer mask method, you could make the script create a selection of the layer mask or vector mask.  Then you can get the bounds of the selection and apply a crop, making sure it doesn't delete the pixels.  Then you could have the script remove the layer mask.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Dec 04, 2013 Dec 04, 2013

Copy link to clipboard

Copied

You could dupe to new document and trim transparent pixels to do the crop. Or hide the other layers and trim.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Dec 04, 2013 Dec 04, 2013

Copy link to clipboard

Copied

That's what I was thinking too, Mike, but the OP wants to keep the pixels that are cropped out.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 04, 2013 Dec 04, 2013

Copy link to clipboard

Copied

I'm not sure if you understood me. I have multiple layers in a document, and I want to trim each layer separately and save it to a file. For instance let's say I have a doc with 2 layers: first layer has bounds == [0, 0, 100, 100], second one has bounds == [100, 0, 200, 100]. The whole doc has size == [200, 100]. So 1st layer takes the left half and 2nd one the right half of the doc. So I need to trim/crop the doc to only the first half, save it, then get the original doc size again, trim/doc to only the second half and save that, too. But trim/crop deletes everything outside of the trimmed/cropped area.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Dec 04, 2013 Dec 04, 2013

Copy link to clipboard

Copied

Seems to me that you only need to keep the cropped pixels because of way you want to do this.

However if you want to do it this way you could create a history snapshot, crop and save the first layer. Then restore the document using the snapshot and crop and save the second.

Or you may be able to just store the current history state in a variable then restore the document using that history state if you are only using a few history states to crop and save.

With a snapshot you don't have to worry about the number of history states but it needs action manager. Storing the current history state can be done using the DOM.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Dec 05, 2013 Dec 05, 2013

Copy link to clipboard

Copied

Damn, I was actually about to ask if I could do a Ctrl+Z (Undo) programmatically but I thought it wasn't possible.

But since I've already implemented the duplication-approach and it works, my question is - would restoring history states be significantly faster than the first approach?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guru ,
Dec 05, 2013 Dec 05, 2013

Copy link to clipboard

Copied

LATEST

the.real.nps wrote:

But since I've already implemented the duplication-approach and it works, my question is - would restoring history states be significantly faster than the first approach?

I think history states would be faster than dupe to new document. How much faster would depend on the size of the document and your system. However I also think that dupe to a new doc is 'safer'. If something goes wrong only the dupe is effected. I think that is why some of the Adobe script use the dupe approach.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines