Skip to main content
Participant
June 16, 2017
Answered

Scripting: Batch selecting/deleting background

  • June 16, 2017
  • 2 replies
  • 5954 views

Hello, I'm trying to write a JS script for Photoshop CS unfortunately I'm very new to js and can't find a way to solve it.

I have a batch of image files with a background that I want to delete/ or set white. Sample images below.

I do it manually with a 'quick selection tool'. I select the tool, press left button in the left top corner and move it right-down-left-top which selects the background. Right click and now I create a new layer via cutting which splits the background and the main picture. I delete the background and save the picture in a different folder.

I tried action manager but it doesnt record everything and it cant select the background.

Thank you for your help

This topic has been closed for replies.
Correct answer morb82035406

Dear JJMack, thank you for your interest.

Yes, that was a poor choice of the images for the example - Dylan Dog looses image data, an error I accept. I'll correct it manually. Unfortunately I don't know how masks work.

I was ambiguous, I want to delete background and/or change it to pure white/other color or just leave it and save it as transparent. Saving it as transparent should work fine /white background jpg is also ok/

Unfortunately if you are not experience in scripting you won't be able to help me. I need it done not done better, unfortunately.

2 replies

Participant
June 19, 2017

anyone else with scripting experience?

/ I don't know why this guy cropped both pictures befor using 'quick selection tool'. I want to select/delete background not crop the picture/

JJMack
Community Expert
Community Expert
June 19, 2017

The guy cropped your image because because he thought you wanted to remove the background from your images.  If what I cropped is what you want to remove you will not be able to automate that unless you make that background more uniform.  The one you posted will not select with the Magic wand or the Quick selection brush stroked across the top or side Stroking all four side sides and recording the strokes with tool recording in a action will work in some cases any object the has a border area that is close to the back ground and all the document need to be the same size for the stroke to be on the four sides.  Here is a screen capture of you two image with the Quick selection tool stroke on the left side. If your background was more uniform the Magic wand  with a low tolerance in contiguous mode sampling 8 point on the edges may work better than the Quick selection tool.  Video uses green screen backgrounds to make removing a single color easier and skin tones doe not have green.  Your Backgrounds are not one color and your colors can be in the borders of your objects.....   You can not select the background with the method you state you use.  Your method may work sometimes.

Here I created a path on all four sides and stroke it with the quick selection brush.  You can see your method only works on one of your image, not perfectly there are border issues and with your first image part of the object was selected and would be removed..

I have a little some scripting knowledge and a lot of experience removing backgrounds.....

You need to understand how Photoshop works better.

I also have a lot of knowledge recording actions so I recorded an action that does what you say you do.  You can download it and batch it you will find it does not works.  I also could not record it with my CC 2017 for If I try to stroke a path with CC 2017 on windows 10 preview CC 2017 crashes so I use CC 2014.  You could try the action in CC 2017. Your CC 2017 may not crash.  I put a white below your second image so you can see the border issues better. Testset.atn

The action I posted does not play in CS2 for CS2 does not have the Quick Selection tool.  The Action Plays correctly in CS6, CC, CC 2014, and CC 2015 and works the way I showed not the way you think it will.  It does not Play in CC 2015.5 and CC 2017 because of Bugs in those versions of Photoshop.  CC 2015.5 anf CC 2017 fail to stroke the path with the quick selection tool because of a program error.  CC 2017 also will crash if I try to stroke a path.  The are quit a few bugs in Photoshop and Adobe keeps adding new ones.

I use CC 2014...............................

JJMack
JJMack
Community Expert
Community Expert
June 16, 2017

morb82035406  wrote

Hello, I'm trying to write a JS script for Photoshop CS unfortunately I'm very new to js and can't find a way to solve it.

I have a batch of image files with a background that I want to delete/ or set white. Sample images below.

I do it manually with a 'quick selection tool'. I select the tool, press left button in the left top corner and move it right-down-left-top which selects the background. Right click and now I create a new layer via cutting which splits the background and the main picture. I delete the background and save the picture in a different folder.

I tried action manager but it doesnt record everything and it cant select the background.

What you wrote above is pure fiction from your imagination.  The example you show  is science fiction.  Two different images with different Aspect ratio size and content. Not a single image example of with and without  a background.

You also can not select the background in either of those images with the manual  method you write you do it with. If that method did work you could record it in an action. You would need to enable tool recording while recording the action.  However, the action would only work on other documents that are the same size and resolution as the document you recorder the action with.  Other size document the tools recording will not work correctly.  

Before you can BS about Photoshop you should learn Photoshop perhaps then you can make your fiction believable.

Your manual method makes these selections

JJMack