Skip to main content
andrews96921672
Known Participant
October 28, 2019
Question

Need help making action to square crop to clipping path.

  • October 28, 2019
  • 3 replies
  • 463 views

I feel this should be so simple but every action I create just will not work on the next image I open. Basically I have all these images of sockets that are currently all square cropped but they are not cropped tight into the image. Every image has a clipping path and the background is dropped out to white. I want to create an action that will select the clipping path, crop to the edge of the clipping path, maybe give a 2 or 3-pixel buffer, and then crop back to square where the object is centered. Any ideas or help?

Images currently look like this - https://imgur.com/quNF3nu

want them to look like this - https://imgur.com/Lo8TyQn

I have about 900 total images to do this too.

THANKS!

This topic has been closed for replies.

3 replies

Bojan Živković11378569
Community Expert
Community Expert
October 29, 2019

You already have good and correct answer. Just to mention, with action which is present in your video, beside changing Crop step to Crop > With Delete Cropped Pixels instead of current Crop step which is recorded using Crop tool and shows where exactly to crop, you must have path named "Path 1" in all your files if you want everything to work as expected.

Stephen Marsh
Community Expert
Community Expert
October 29, 2019

Your action has recorded explicit crop sizing info, whereas my action has not:

 

 

Just use Image > Crop with the selection loaded from the path, rather than the crop tool or another method that may introduce unwanted size info into the action.

 

P.S. You can also use the action panel menu to "insert menu command".

 

If you are still stuck I can share the action...

JJMack
Community Expert
Community Expert
October 29, 2019

Basically Stepen's action just uses menu Image Crop. That will do a tight rectangular crop to the bound of the current active selection.  The crop will most likely not be square or have any side that is 2000 pixels. After the crop his action uses fit image  to resizes the crop so at least one side will be the correct size.  He then adds canvas to make the image square.  It can be a little tricky to record the canvas size step because you need both width and height recorded into the action step and because one side is correct only the other side change values will be recorded into the step.  After the set Path 1 as a selection  he used expand selection to give you the white background area you want.  If you leave out the expand  the action will do a very tight crop to the produces bounds.  You then do the Fit Image resize little smaller than you want the image to be like 1980px by 1980px then do the canvas size 2000px by 2000px you will get your white background and the canvas size step will record both sides for both will be changed.

JJMack
Stephen Marsh
Community Expert
Community Expert
October 28, 2019

Something like this should do it:

 

 

Notice how there is a fixed target size in pixels for both the fit image command and the canvas size command.

 

If the paths don't have a consistent name, you could use the "select image" command or the "trim command" set to the upper left or lower right pixel colour – or even a luminosity based selection.

 

andrews96921672
Known Participant
October 28, 2019

Any way you could send me that action for me to try?

 

Here is a little screen grab showing you the current action I made. It works on the first image, the one I made it on perfect. Then the second image does way too much. Its something to do with setting the rectangle crop a certain size and I don't know how to change that.

 

I just want it to select the clipping path, move out like 3 pixels, and then crop. Then I can run my 2000x2000 action to square it up. 

 

https://www.dropbox.com/s/8ohzgrua8fncxyu/scrpit.mov?dl=0