Skip to main content
Mattmcquiff
Inspiring
April 22, 2016
Question

Non Destructive Trim, protect the layer below

  • April 22, 2016
  • 2 replies
  • 2154 views

I am trying to script this. I want to be able to trim a layer, then expand the canvas by a set amount. Then reveal the 'whole layer' below. I can do all of this, but the issue I have is I need to trim a layer, but keep the deleted pixels of the layer underneath.

My method prior to using trim is to hide the other layers then 'trim'

Un hiding the layer then use reveal doesn't work as it has been deleted during  trim How can I lock a layer so that this is protected?

Matt

This topic has been closed for replies.

2 replies

JJMack
Community Expert
Community Expert
April 23, 2016

I think you could come close to scripting a layer trim. The way Photoshop "Trim"  works  thought trims the boundaries transparence or a boundary selected color around an object its a document crop that applies to all the layers in the document.  I do not think  this is what you want.  You do not want to crop the document  and it makes no sense to trim a layer outer border transparency.  IMO the only thing the makes sense is tinning a layers border color that is around a object.

The Problem is a layer can be any shape.  You can get the layers bounds but you can not be sure that a point like the top left corner will have a color pixel or be empty..   You may be able to program a loop with a  try catch  where you try sampling a point like top left corner with the magic wand.  if the magic wand fails to select pixels the catch would change the sample point.  When the magic wand is successful the script would clear the selection trimming the layer boundary color about a subject and break out of the magic wand forever loop and the script would end.

Edit 4/24/2016

I tried but there is a Problem with my Magic Wand idea.  The Magic wand will not fail if the sample area is empty.  It will select all the contiguous empty area.  So my Try Catch ideal was bad guess. All I can up with was to sample 8 points about the layer'e bounds. Eight shots in the dark.

JJMack
c.pfaffenbichler
Community Expert
Community Expert
April 22, 2016

You can use the ActionManager code (as recorded with ScriptingListener.plugin) recorded when using the Crop Tool.

Mattmcquiff
Inspiring
April 22, 2016

I'm fine using that above, but I don't think helps with what I am trying to achieve.

Something like this

Layer1 Main

Layer2 Background (Now Hide it)

Select Layer 1 Main

trim basing trim on transparent pixels

Unhide Layer 2 Background

Reveal all

c.pfaffenbichler
Community Expert
Community Expert
April 22, 2016

Just use the bounding box to determine the intended Crop and use the Crop Tool with »Delete Cropped Pixels« unchecked.