Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- import math
- def numToHex(num):
- if num < 10:
- return str(num)
- elif num == 10:
- return 'a'
- elif num == 11:
- return 'b'
- elif num == 12:
- return 'c'
- elif num == 13:
- return 'd'
- elif num == 14:
- return 'e'
- elif num == 15:
- return 'f'
- def encode(input):
- string = ""
- inImg = Image.open(input)
- width = inImg.size[0]
- height = inImg.size[1]
- # encode image 2 into a copy of image 1
- for y in range(height):
- for x in range(width):
- pixel = inImg.getpixel((x, y))
- for i in range(3):
- string += numToHex(pixel[i] // 16)
- string += numToHex(pixel[i] % 16)
- print(string)
- return string
- def putContents(file, string):
- with open(file, "w+") as f:
- f.write(string)
- putContents("converted.txt", encode("image.png"))
Advertisement
Add Comment
Please, Sign In to add comment