def encode(image, number):
'''Encodes the key into the image. Note: number is the str of a bin!'''
width, height = image.size
# Make sure that the image is large enough
if width < len(number):
return False
line = randint(0,height)
column = width - len(number) -1
px = image.load()
for i, char in enumerate(number):
i += column
color = ((px[i, line][2] // 10) * 10) + int(char)
px[i, line]= (px[i,line][0], px[i,line][1], color)
image.save('encoded.png', 'PNG', quality=100)
return True
评论列表
文章目录