ps的色相值调整是相对原图的基础左右调整的,这里最后的效果是对应ps色相调整的效果,ps的ctrl+u弹出调节色相窗口
def change_color():
image: PngImageFile = Image.open("img/entrance1.png")
hue_offest = (180.0) / 360.0
bg : PngImageFile = Image.new("RGBA", (image.size[0], image.size[1]))
for i in range(image.size[0]):
for j in range(image.size[1]):
try:
r, g, b, alpha = image.getpixel((i, j))
h, s, v = colorsys.rgb_to_hsv(r, g, b)
if hue_offest > 0.0:
h = h + hue_offest
else:
h = h - hue_offest
if h <= 0.0:
h = -h
elif h > 1.0:
h = h - 1.0
r, g, b = colorsys.hsv_to_rgb(h, s, v)
# 防止精度损失
r += 0.0000000001
g += 0.0000000001
b += 0.0000000001
r = int(r)
g = int(g)
b = int(b)
bg.putpixel((i, j), (r, g, b, alpha)) # 值必需要int类型,不然没效果
except Exception as e:
continue
# bg.save("output/save.png")
bg.show()
pass