Skip to main content
TonyDanger
New Participant
July 3, 2019
Question

Script to remove a white background, insert another image & resize to square?

  • July 3, 2019
  • 5 replies
  • 3738 views

Hey Folks,

I have a problem that I'm not sure how to get around. I have a folder of approx 4500 images, all of them have a product in the center on a white background, and all are at a scale of 4*3 (1200px*800px or 2400px*1600px) like this image below:

What I need to do is make sure they are all sized to 1200*800, extend the canvas to 1200*1200, select & remove the white background on all of them, replace it with another image / gradient as background.

Is this possible? I know I can use Actions to do the product resize & canvas resize steps, but I'm not sure about the background.

Thanks

This topic has been closed for replies.

5 replies

Grant H
Adobe Expert
July 4, 2019

I am sorry to disagree. trim WOULD work PERFECTLY with a white background ... here is a video to show exactly that. I use this to batch many photos according to client size specifications and works like a charm.:

auto cropping to size - YouTube

/G

TonyDanger
New Participant
July 4, 2019

But the trim doesn't remove the white background. As above, I need to resize the canvas, remove the white background & add a textured background (whether it's a colour, gradient or another image isn't decided yet). Like how JJMack has done above you.

Grant H
Adobe Expert
July 4, 2019

ohhhh, sorry. I mis read that (replacing BG) okay now it makes sense.

JJMack
Adobe Expert
July 3, 2019

You will most likely want some space around your products image.  If the  background is white and you trim the white background the will be no space around your  product and the white background will still be there.  Trim will also not work well if the  background is not pure white if there are grays or shadows trim will not trim to your product.  So If I were you I would record an action that tries to remove the white background with something like the Magic wand tool then trim transparent background. Fit the  trimmed product images to smaller area like 1190x1190 then add canvas 1200x1200. Add an empty layer  fill it with you gradient then move that layer to the bottom of the stack.

JJMack
TonyDanger
New Participant
July 3, 2019

The current resolution of images is always either 1200*800 or 2400*1600 (So 4*3). So switching them to 1200*1200 would give me the whitespace on the top & bottom needed (horizontal size is fine to stay as is).

As you say, trim wouldn't work as we need to remove the white background, using the Magic Wand with a tolerence <5 should be fine. Can I run the recording of that automatically on all 4500ish images? I'm assuming it would be similar doing the same to add a new background & saving as a .jpg?

JJMack
Adobe Expert
July 3, 2019

The OP has a Major Problem the white background in their example image can not be automatically removed because, There is no contrast between part of product edge and the white background. That would require an AI Magic wand or quick selection tool.

JJMack
Grant H
Adobe Expert
July 3, 2019

the script I used in it was to make it square

Grant H
Adobe Expert
July 3, 2019

easy with actions Tony.

start the action with a trim ... here is a screenshot of how it should look more or less:

July 3, 2019

Hi

You may be better off posting on the Photoshop Scripting forum

I can move this thread for you if you like

TonyDanger
New Participant
July 3, 2019

Whoops, yes please!