def getwebsafe(r, g, b):
    rw = 51 * ((int(r) + 25) // 51)
gw = 51 * ((int(g) + 25) // 51)
bw = 51 * ((int(b) + 25) // 51)
return rw, gw, bw
How to round an RGB value to the closest web safe value with PIL (Python Imaging Library)?