Skip to content

Instantly share code, notes, and snippets.

@sumanthratna
Last active May 1, 2020 00:28
Show Gist options
  • Save sumanthratna/8958b9e62f61cc3b9746e3f79634ee5d to your computer and use it in GitHub Desktop.
Save sumanthratna/8958b9e62f61cc3b9746e3f79634ee5d to your computer and use it in GitHub Desktop.
Generate a macOS user icon that blends in with the login or desktop background.
import numpy as np
from PIL import Image
sub = np.abs(np.array(Image.open('LESGO.png').convert('RGB')) - np.array(Image.open('day.png').convert('RGB')))
mask = np.zeros((sub.shape[0], sub.shape[1]))
sub_gs = np.array(Image.fromarray(sub).convert('L'))
mask[sub_gs > 0] = 1
final = np.array(Image.open('day.png').convert('RGB'))
final[mask == 0] = [0, 0, 0]
Image.fromarray(final).save('final.png')
  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, set final to zero when mask is 0, and save final to final.png
  8. 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment