I have almost 700 small images of glyphs which are anti-aliased black on white backgrounds. All the files have excess whitespace and I wanted to use the trim function in Photoshop to batch resize all the images using an action. However, it turns out there are some non-perfectly white pixels throughout all the files causing very inconsistent trimming. By using the paintbucket tool with a tolerance of 1 I am able to manually fix the backgrounds but I don't want to do that 700 times. Is there a way to clean up these backgrounds using an action in batch processing?
Create an action with the following steps.
- Levels: Boost the white point enough to handle most, if not all, of the images.
- Select Pixels: From the Channels panel, Ctrl+click to select the active pixels in the black channel. Or, if in RBG, select the active pixels in R, then Shift+select the active pixels in G as well as B.
- Selection: Invert the selection so that the marquee is around the black. (Invert the marquee SELECTION, not the actual pixels)
- Selection: Expand the selection by a few pixels to create a safe zone. This helps round shapes to not have flattened sides at the boundary.
- Crop: Crop to the expanded selection. This will ensure that the glyph is centered with an even white space around the glyph.