Using ImageMagick:
$ convert image.png -crop '1x1+100+200' txt:-
Outputs, e.g.
# ImageMagick pixel enumeration: 1,1,255,rgb
0,0: (236,236,236) #ECECEC rgb(236,236,236)
Or, if the file is PNG-24 file, it outputs e.g.
# ImageMagick pixel enumeration: 1,1,255,rgba
0,0: ( 0, 0, 0,243) #000000F3 rgba(0,0,0,0.952941)
At -crop
option I've first defined the area to be cropped, which in this case is 1x1 pixels. Then I've defined the location of the crop relative to the North West corner, i.e. upper left.†
Lastly I've converted the output to textual with txt:-
. ImageMagick then outputs all the colors of the image to STDOUT (in this case there is only one color, as the image size is 1 pixel), meaning you could process it with normal shell techniques. So e.g. by piping the output to tail -n 1
you would get only the pixel info line.
If you need the pixel's color in any other colorspace, you should look at the aptly named -colorspace
option.
†) Actually the location is relative to the specified -gravity
value, but it defaults to "NorthWest".
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.
Layer Menu > Layer Mask > Hide selection
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.
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.
Undo the Invert (or Invert again) then Opt/click the Mask & Invert.
That's your 2nd mask. Again save as png.
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.