Greasy Fork is available in English.

Google Voice Favicon Alerts

Alerts you to the number of unread items in Google Voice.

< Feedback on Google Voice Favicon Alerts

Review: Good - script works

Ben WengerAuthor
§
Posted: 12/11/2020

In case it helps someone, here is the python script I made to convert the 32-bit depth PNG icon to the correct string needed by the userscript. Just update the file name. String output will save to Output.txt.

from PIL import Image
import numpy as np
im = Image.open('logo_voice_2020q4_color_1x_web_64dp-2.png', 'r')
im = im.resize((16, 16), Image.LANCZOS)
width, height = im.size
pixel_values = list(im.getdata())
pixel_values = np.array(pixel_values).reshape((width, height, 4))
pixmap = ''
for x in range(width):
for y in range(height):
rgba = pixel_values[x][y]

canvas = 'rgba(' + str(rgba[0]) + ',' + str(rgba[1]) + ',' + str(rgba[2]) + ',' + format(rgba[3]/255, '01.5f') + ')'

if y == 0:
pixmap = pixmap + '["'
pixmap = pixmap + canvas
if y < (width - 1):
pixmap = pixmap + '","'
else:
pixmap = pixmap + '"],'

pixmap = pixmap[:-1] #remove last ',' character
pixmap = '[' + pixmap + ']'
#print(pixmap)
with open("Output.txt", "w") as text_file:
text_file.write(pixmap)

Post reply

Sign in to post a reply.