Generating a mask png from a color image

graphicsimage editing

Apple requires certain icons to be monochrome masks with transparency in png file format.

How (on macOS, using a built-in app, such as Preview, or an app in the App store, such as Pixelmator) can I convert an existing color image (png file), so that one color (a background) becomes transparency, and everything else becomes either pure black or pure white?

Is it then possible to invert a mask? (transparency becomes black or white, and any non-transparent areas becomes transparent)

Best Answer

You can do this in Photoshop, & I would imagine Pixelmator or any other decent graphics package could in a similar manner…
Invert Colour can also be done in Gimp - freeware, open source. If you want to use Gimp, then I'd recommend this Mac-specific build from https://www.partha.com/ which looks & feels far more 'Mac-like' than the official build.

Load your image, use the Magic Wand or equivalent to select the background.

enter image description here

Layer Menu > Layer Mask > Hide selection

enter image description here

You've now generated the basic mask shape.
The next bit is a bit fiddly, but you can automate it for future use.

Opt/click this new mask, then select all. Copy, click the picture item in the Layer, Paste. This will generate a new layer containing the black & white image of your mask.

enter image description here

Drag your original mask to the new layer (both thumbnails will then look the same.)
Disable your original layer to save confusion.
Click the main image in the thumbnail & Invert (Cmd/i)
That's your first mask. Save as png.
PNG with transparency is a 32-bit file rather than 24. Some apps differentiate this way, others including Photoshop have a dedicated "save Transparency" option which changes the bit depth for you.

enter image description here

Undo the Invert (or Invert again) then Opt/click the Mask & Invert.
That's your 2nd mask. Again save as png.

enter image description here

You could, of course, do each of these as a new layer, then saving your file as PSD or other native format would preserve all assets in a single file.