Creating a macOS user icon that blends with your background

April 10, 2020 | 0

I'm a macOS user. I really only have one complaint (it's actually very minor): there's no simple default login icon, like the typical lifeless gray/white/blue person. I decided that I wanted my icon to completely blend in with the login background. There was only one problem—I had no idea how to do this.

I decided to actually figure this out since the red rose was bothering me. I came up with the following (horribly inefficient) psuedocode/algorithm to do this:

  1. take a screenshot of the login page and name it log.png
  2. take a screenshot of your home page and name it desk.png
  3. in Preview, use the ellipse selection tool to select the current/bad icon in log.png
  4. in Preview, copy the icon with ⌘-C, paste it onto desk.png, and save this to a new file called newdesk.png
  5. in Python, subtract newdesk and desk (this should leave an image array with many zeroes and some non-zero numbers where the old icon was)—name this new array sub
  6. in Python, convert sub into a binary mask by setting all non-zero pixels to 1, name the mask mask
  7. load either log or desk (your choice) into a variable named final and set final to zero when mask is 0
  8. save final to final.png
  9. in Preview, use the ellipse selection tool to select the new/good icon in final.png, click crop, and save this to a new file called icon.png

This resulted in the following Python code (numpy 1.18.2 and Pillow 7.1.1):

I'm sure this can be made much more efficient with advanced N-dimensional array indexing, but that usually sacrifices code readability. Please contact me if you have ideas on how to make this faster! Note: the final product isn't perfect.