• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

Community Beginner ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

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:

example.jpg

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

TOPICS
Actions and scripting

Views

3.2K

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe
Guest
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

Hi

You may be better off posting on the Photoshop Scripting forum

I can move this thread for you if you like

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

Whoops, yes please!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

easy with actions Tony.

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

Screen Shot 2019-07-03 at 15.17.12.jpg

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

the script I used in it was to make it square

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

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?

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

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.

Capture.jpg

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

Yes, you're right with that example. I think there will be a handful like that where I will have to manually tweak them, but overall we don't have a huge amount where there are edges that are clipping white due to the studio spots.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

In this case select subject does a slightly better job than Magic Wand or Quick Selection tools.

Capture.jpg

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 03, 2019 Jul 03, 2019

Copy link to clipboard

Copied

Easy fix if you save Layerd files

JJMack

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 04, 2019 Jul 04, 2019

Copy link to clipboard

Copied

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jul 04, 2019 Jul 04, 2019

Copy link to clipboard

Copied

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 04, 2019 Jul 04, 2019

Copy link to clipboard

Copied

LATEST

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines