What's new
Photoshop Gurus Forum

Welcome to Photoshop Gurus forum. Register a free account today to become a member! It's completely free. Once signed in, you'll enjoy an ad-free experience and be able to participate on this site by adding your own topics and posts, as well as connect with other members through your own private inbox!

Automated Trim/Crop


Rendor

New Member
Messages
4
Likes
0
Hi all,

I was wondering if I could receive some help on a topic I am currently trying to solve at work. Basically I am an image manipulator with the job of preparing hundreds and thousands of images for our website; the images must be a set size and must be cropped to include a slight white border around the edge. For example, I may receive hundreds of images that have a product in the center of the image as shown below:

img].jpg

Now what I spend most of my day doing is simply cropping/trimming an image to cut out the area around the red line as shown here:

img] (1).jpg

Now our next project consists of over 20,000 of these images in this exact same state. I know about the Trim tool and I was thinking about the possibility of automating a Trim to take the images down to the very edge of the product and then using a script to add a white border of say 50px all the way around the image. However, I am unsure how I would go about this. Is there a way to do it like that, or is there a script out there already that would allow me to do something similar? As you can imagine the thought of carrying out this process for 20,000 images is a bit daunting so any help or tips will be greatly appreciated!

Thanks
 
Last edited by a moderator:

colleague

Guru
Messages
824
Likes
1,254
you can make an action that does the following steps

1) trim
2) resize canvas

but maybe you also can use
file - automate - fit image after the trim

and with this action you can go to "file - automtic -batch"
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
When I have had a task such as this, one problem that I encountered was that the presumably white background in the starting image was not actually true white, but was only near white. Even worse, the whiteness varied from area to area as you move around the image. Because of this, since the "trim" tool has no tolerance or threshold adjustment, and only works on the pixel value in one of the corners, it never worked very well. In fact, often it trims away nothing, or nearly nothing.

However, there is an easy work-around (that can be made into an action).

Make a temporary copy of your image in the layer stack, and run the threshold tool on it. By looking at the RHS of histogram shown in this tool, you'll immediately see just how imperfect the white background really is. Move the threshold control to the left just enough to include all the near-white areas. Then, with the black and white thresholded layer selected, use the trim tool on it. Next, turn off / delete that temporary layer, and you should see a much more useful trim job. As your final step, you can add back a fixed width white border, 50 px, or whatever is needed.

Just my $0.02,

Tom M
 

ALB68

Dear Departed Guru and PSG Staff Member
Messages
3,020
Likes
1,332
Experimenting with this a bit. It appears that the Trim command works best with transparent pixels. Are the images your going to do, all the same size to begin with?
 
Last edited:

Tom Mann

Guru
Messages
7,223
Likes
4,343
Larry, that's exactly why I suggested use of the threshold tool to generate a temporary layer, parts of which are all exactly 255,255,255 (or completely transparent). Trim just doesn't like slightly off white, or slightly non-transparent pixels.

Tom
 

ALB68

Dear Departed Guru and PSG Staff Member
Messages
3,020
Likes
1,332
Larry, that's exactly why I suggested use of the threshold tool to generate a temporary layer, parts of which are all exactly 255,255,255 (or completely transparent). Trim just doesn't like slightly off white, or slightly non-transparent pixels.

Tom
Tom, not to dispute what your saying at all. To me a better way would be to just make the pixels outside of the redline transparent and then trim. I simply used the magic wand, set to 32, and contiguous checked. Selected those pixels, entered Delete, then Trim. Works perfectly. Next problem is adding back the border. Question would be could the pixel selection be automated with an action with human interaction required. Not very experienced with these.
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
Larry: "...just make the pixels outside of the redline transparent and then trim...."

Ahh, that's interesting, Larry. I could be wrong, but I assumed that the photo the OP receives does not contain the red line/box, and he put included it in his post simply to illustrate what he wants. I assumed what he has to work with looks more like the 1st image he posted. Hopefully, he'll reappear and clear this up.

Anyway, my experience is that either a threshold or a contiguous magic wand preparation step gets one to essentially the same point, ie, either all white, or completely transparent pixels in the periphery, and then the trim command works perfectly. I never saw much difference between the two approaches, as long as the white area is *really* white.

Cheers,

Tom
 

MrToM

Guru
Messages
3,595
Likes
3,321
Is the OP still interested in this?

I've written an action but I could do with some example images for testing.

Regards.
MrTom.
 

ALB68

Dear Departed Guru and PSG Staff Member
Messages
3,020
Likes
1,332
Larry: "...just make the pixels outside of the redline transparent and then trim...."

Ahh, that's interesting, Larry. I could be wrong, but I assumed that the photo the OP receives does not contain the red line/box, and he put included it in his post simply to illustrate what he wants. I assumed what he has to work with looks more like the 1st image he posted. Hopefully, he'll reappear and clear this up.

Anyway, my experience is that either a threshold or a contiguous magic wand preparation step gets one to essentially the same point, ie, either all white, or completely transparent pixels in the periphery, and then the trim command works perfectly. I never saw much difference between the two approaches, as long as the white area is *really* white.

Cheers,

Tom

It is a trifle confusing. I believe your right. Didn't read closely enough. But why is he adding a white border?
 

MrToM

Guru
Messages
3,595
Likes
3,321
I just followed the OP's directions...

I was thinking about the possibility of automating a Trim to take the images down to the very edge of the product...

...and then using a script to add a white border of say 50px all the way around the image...

...seemed simple enough although there is no need for a script, it can all be done in PS directly.

What's confusing you Larry?
What the OP wanted or something else?

Regards.
MrTom.
 

ALB68

Dear Departed Guru and PSG Staff Member
Messages
3,020
Likes
1,332
I just followed the OP's directions...



...seemed simple enough although there is no need for a script, it can all be done in PS directly.

What's confusing you Larry?
What the OP wanted or something else?

Regards.
MrTom.

OK MrTom..I am now interpreting this to mean that he simply wants to crop these down to a standard size (inside the red line). Then he says "add a white border" . The background (I assume) is already white. I'm missing something here. , why the border? When I first looked at it, I downloaded the one with the red line. I was thinking the working image was that one, apparently not as Tom Mann pointed out. (brain is getting old and worn out..lol)
 

MrToM

Guru
Messages
3,595
Likes
3,321
Ah....maybe you missed this bit between the images...

Now what I spend most of my day doing is simply cropping/trimming an image to cut out the area around the red line as shown here:

Quite why some posts come out in this dark text I don't know but its a right pain in the butt with the dark theme.....makes text very easy to miss.

Maybe that makes it clearer as to what the OP wants to do?...and explains the red box.

If only the OP would respond we could get it sorted....I've done the action already but I need to know the final size required.....some example images wouldn't go amiss either.

Regards.
MrTom.
 

ALB68

Dear Departed Guru and PSG Staff Member
Messages
3,020
Likes
1,332
Ah....maybe you missed this bit between the images...



Quite why some posts come out in this dark text I don't know but its a right pain in the butt with the dark theme.....makes text very easy to miss.

Maybe that makes it clearer as to what the OP wants to do?...and explains the red box.

If only the OP would respond we could get it sorted....I've done the action already but I need to know the final size required.....some example images wouldn't go amiss either.

Regards.
MrTom.

"to cut out the area around the red line as shown here:



"around" implies outside to me. I didn't read it thoroughly, apparently the line is imaginary to show the crop bounds.
Yes, would be nice if some feedback from the OP would occur.
 

Tom Mann

Guru
Messages
7,223
Likes
4,343
Hi Larry -

With respect to your question about why the OP requested a border of 50 pixels, my strong suspicion is that the OP is given images where the size (in pixels) of the product can vary by quite a bit, and, but more importantly for this discussion, there will always be different amounts of white space around the product in each of the photographs.

My strong suspicion is that it's the job of the OP to prepare images for publication in which the product being sold always should be about the same size, and this size should always be a nearly fixed percent of the total space allotted to each image (eg, the column width for a print catalog, etc.).

So, after the image is trimmed down to a tight bounding box (rectangle) that just touches the product on each side, by experience, he probably knows that if he adds back 50 pixels of white around the tight bounding box, each image will wind up with a nice fill factor -- not too small a fraction of the space allotted, and not to close to the edges, either.

Anyway, that's what I am pretty sure is going on.

Cheers,

Tom
 

Top