Google Voice Favicon Alerts

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

< 腳本Google Voice Favicon Alerts的回應

評論:正評 - 腳本一切正常

Ben Wenger作者
§
發表於:2020-11-12

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)

發表回覆

登入以回復