Skip to main content
July 9, 2009
Question

Making background of photos white via script

  • July 9, 2009
  • 2 replies
  • 1828 views

CS3/CS4 Javascript    

Hi Everyone,

I am sure it is possible to remove backgrounds from images in fact I just read http://forums.adobe.com/message/1115191 and Paul Riggott's script worked great for a pure white background.

Id like to know if you can script the use of the magic wand with a tolerance of maybe 20, contiguous checked and anti alias checked that selects from an upper left corner of the image where the background would be to select the entire background (assuming that a white paper background has many greys in it with shadow). And then id like the selection to be filled with white.

Is this doable or perhaps there a better way to do it?

Thanks very much in advance.

Jason

This topic has been closed for replies.

2 replies

Reynolds__Mark_
Inspiring
July 10, 2009

You'd be better off doing this with an Action.

July 10, 2009

Very interesting about the color range i didnt even think of that. I tried it in an action and it works really well so i might be able to use it. I also have to resize to fit certain dimensions which is trivial in the action.

Great tip and I dont have to tear my hair out scripting it! I marked your reply as helpful instead of the answer by mistake.

Xbytor2 thank you for your reply too!

Thanks again

-J

Reynolds__Mark_
Inspiring
July 10, 2009

The Magic wand will work with an action too. Only problem is it has to be used in a specific area. So you have to KNOW that top left pixel is 100% white, in each file. Color Range is a better tool anyway, generally when using color selections in Actions use color range because it can draw the entire image. (localized color clusters OFF)

Inspiring
July 9, 2009

Two lines of code with xtools/xlib/stdlib.js:

Stdlib.magicWand(app.activeDocument, 0, 0, 20, true, true);

app.activeDocument.selection.fill(Stdlib.COLOR_WHITE);

But if you don't want to @include stdlib.js, you can use script listener code for the magic wand call and manually construct WHITE for the fill.

-X