Copy link to clipboard
Copied
Hi friends,
I'm looking for a script that detects a subject and crops the image.
Workflow
I get thousands of RAW files with a wide framing. Same camera all over the shooting, same pixel dimensions. Models move and change pose.
I develop on C1 and export PSD files.
Work on the PSD files and export JPEG for the client.
Script
Detect Model's height and crop leaving a few pixels above the head and bellow the feet.
Model should be centered on the image.
Keep aspect ratio 2:3.
Input files
https://www.dropbox.com/sh/gbufidhfqic1f4b/AADlTLSsfwDxTDBL-RcQHAxxa?dl=0
Thanks in advance!
Thanks all for your help!
After reading all the proposals I came out with an action. Please take a look at it and let me know your comments.
The action runs auto-select, expands the selection 35px, creates a filled temp layer, transforms and uses the trim command.
To keep the 3:2 proportion I considered the model's height:
Width = 0.667 × Height
Once the model's height is "mapped" by the autoselect command I just copy the selection, rotate 90° and contract the width to 66.7%.
Then trim transparent pi
Copy link to clipboard
Copied
C1?
Copy link to clipboard
Copied
Capture One
Copy link to clipboard
Copied
If you are using Adobe Experience Manager for your ecommerce site - it has this capability baked in called "Smart Crop". It uses AI to detect subjects and auto crop to an aspect ratio.
Unfortunately I'm not sure Photoshop has an AI functionality that will take the subject into consideration.
Any action would crop based on physical parameters risking cutting the subject off.
Copy link to clipboard
Copied
Look at Select->Select Subject which is designed for this kind of use. I don't know if it is scriptable or requires Action Manager code.
Copy link to clipboard
Copied
The issue with Select subject is the crop is made directly on the selection, not at an aspect ratio.
It gets you part of the way there, and you could expand the selection to give breathing room to the crop, but I'm stumped how to take the end selection and convert the crop from "Selection" to Aspect Ratio.
You lose the selection as soon as you attempt to convert.
Copy link to clipboard
Copied
Selection->Expand, Image->Crop, Image->Canvas Size
That's how I would do it. Crop works with the bounding box. Or delete above and below the selection and then set the canvas size.
Copy link to clipboard
Copied
You could save the selection bounds to a variable and parse them to create a rectangular selection with the margin you want. Feel free to copy the function below.
// Grab the selection
var bnds = app.activeDocument.selection.bounds;
var someMargin = 50;
// Use selection as parameters. To avoid headache, use the values (so without UnitType)
makeSelection(bnds[0].value,bnds[1].value,bnds[2].value,bnds[3].value, someMargin);
function makeSelection(lft,top,rgt,btm, margin){
var w = rgt - lft + margin*2;
var h = btm - top + margin*2;
var wM = (rgt+lft)/2;
var hM = (btm+top)/2;
// If landscape, update top&bottom, if portrait update lft&rgt
var lft = (w<h) ? (wM - h/2) : lft;
var top = (w<h) ? top : (hM - w/2);
var rgt = (w<h) ? (wM + h/2) : rgt;
var btm = (w<h) ? btm : (hM + w/2);
lft -= margin;
top -= margin;
rgt += margin;
btm += margin;
// Triggers a new selection, note the array of arrays if you want to play around with it
app.activeDocument.selection.select([[lft,top], [rgt,top], [rgt,btm], [lft,btm] ]);
}
Copy link to clipboard
Copied
I programed a Photoshop Plug-in Script toe be recorded ins Actions to create Aspect Ratio selection and Paths the are retanglar or elliptial shape. It is in Crafting Action Package. Its Dialog is use recording the Action Step from menu File>Automate>Aspect Ratio Selection... looks like this and the seletion will be orianted lye the imags oriantation landscape or portrait to loose less image content.
Copy link to clipboard
Copied
The methods in the following topic thread can be easily modified for your task, it is almost the same:
Copy link to clipboard
Copied
I have adapted the action/helper scripts from the previously linked topic thread to crop to 2:3 aspect ratio. The action relies on three key functions:
1) Select menu > Subject
2) Helper script: Add Guides to Selection Bounds
3) Helper script: FitImageToGuides
The action and helper scripts are all available for download here:
Downloading and Installing Adobe Scripts
Mac OS Example:
/Applications/Adobe Photoshop CC 2018/Presets/Scripts
Win OS Example:
C:\Program Files\Adobe\Adobe Photoshop CC 2018\Presets\Scripts
Further information at the Adobe site:
Scripting
NOTE: If running, Adobe Photoshop must be quit and restarted for newly added scripts to become accessible.
Copy link to clipboard
Copied
All provided scripts are excellent. I would personnaly use a simpler script (no coding) doing the following :
Done
Copy link to clipboard
Copied
didiermazier what am I missing in your post? How does this preserve the 2:3 aspect ratio in the cropped image, which is a key requirement of the OP?
"Script
Detect Model's height and crop leaving a few pixels above the head and bellow the feet.
Model should be centered on the image.
Keep aspect ratio 2:3."
There is a reason for the scripting leveraged by the action in my previous post, my approach results in a 2:3 aspect ratio crop, with the model centred and a small amount of space above/below the subject. Just as the original posters images show:
Copy link to clipboard
Copied
My bad!
In this case there is a much simpler way :
Use content aware scale (alt+shift+ctrl+c) and you are good to go
Copy link to clipboard
Copied
here is a video : crop
it is a little tricky with percentages and resolution but it works fast no?
Copy link to clipboard
Copied
Hi didiermazier I watched your video, however, I personally would not use or recommend that approach.
The content-aware scale method that you show took approx 52 seconds to run. It is all manual. Unless I am missing something, the image is destructively resampled.
The goal is to automate repetitive editing of 1000's of images.
My action/script based workflow takes around 8 seconds to run (on my computer, so YMMV faster or slower) and can be used in Batch/Image Processor/Image Processor Pro for unattended automation of many images. The result is a 2:3 crop without any resampling.
As the saying goes "to each their own".
Copy link to clipboard
Copied
This video just show the base process.
Then of course you will record this as an action and apply to your 1000 pics as well with the batch processor.
The idea was just to find an alternative way using photoshop native features without coding.
But you are right the exec time is longer for each pic. Time to take a break for instance.
😉
It occures to me another stupid no coding solution :
If your computer is strong enough open these images with Camera Rawthen select all of them and apply the 2:3 croping to all of them in just one step
Then instead of opening them, just save and set up the new folder
And you are done
Copy link to clipboard
Copied
I swear this is my last post on this thread!
There is a definitively simpler way to achieve the 2:3 crop with PS native features
Here is a video showing the process (and action recording): CROP 2
…
Easy to record, easy to batch process the 1000 pics
Copy link to clipboard
Copied
Video is unavailable.
Copy link to clipboard
Copied
"I swear this is my last post on this thread!"
I don't want this to be your last post on this thread, please don't take my constructive criticism the wrong way either... There is a reason that I suggested the approach that I did.
Unfortunately the 2:3 ratio crop tool recorded in an action will record absolute pixel values and not the relative values entered into the toolbar:
I did try your second video, the action screenshot is above, so unless I misunderstood, the method resulted in uneven/incorrect crops... But they were 2:3 ratio! I tried Batch, Image Processor and Image Processor Pro all using the same action.
I'm with you, I wish that there was an easy way without scripting to do this using only native methods.
P.S. I missed your earlier ACR suggestion, and while a nice idea, each image is too variable – the subject is not in the same size/position each time and the result is inconsistent, even among the 5 sample images provided, let alone thousands.
Copy link to clipboard
Copied
I swear I will never swear!
Your critism is welcome because it makes me go further. We all are here to find solutions.
In fact when checking what I proposed I found evident problems that I did not take in count at first time :
I will work on a better action using doc size and the align for the crop frame.
Again I am not competing. All solutions are good to take!
Best
Didier
Copy link to clipboard
Copied
Exactly Didier!
When the only tool you have is a hammer, even a screw looks like a nail.
I too hope to learn something, there is a good reason for my action/helper script combo, but I could be missing something too. It would not be the first time that I have over thought something!
Copy link to clipboard
Copied
Hey I think I finally found a way to get all pics same size and 2:3 what ever the model height is…
Once the Select/enlarge/crop is done the trick is setting image size for the height and then setting canvas width.
Here is the video : CROP 3
Copy link to clipboard
Copied
Hi didiermazier - OK, that works as far as it goes, however, it is resampling the images as a hack work-around to get to the 2:3 aspect ratio. Now if you can come up with a method that does not resample, then that would be something! This is why I relied on scripting where necessary.
maurom15189996 did not specify that the images should be resampled/resized, however, if that is acceptable then the job is done.
My action cropped without resampling/resizing, which is why I had to use helper scripts to do the things that Photoshop can't do with native tools and recorded steps.
Copy link to clipboard
Copied
You are right and there is another issue with this lasr solution :
you have first to check max height of the smaller girl in order to find the propee measure for the resizing.
this is why I choose 3000 px to be sur that I would not alter the pics enlarging them.
relatîg to resampling you are facing two choices : resampling or get a variable margin up and down.
when you resample all models have the same height no matter mother nature… same size same margin.
and lasr since the pics are Jpeg I suppose their destination is Web. In this case 3000 px is way to much…
was interesting thread !