Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # PIL 은 Pillow 라이브러리를 설치해야한다. (using PIL need to pillow library) pip install pillow
- # python3 pixel2text.py <image filename> [output filename]
- # output filename은 생략 하면 output.txt 로 지정됨
- import sys
- from PIL import Image
- from PIL import ImageOps
- def main(argv):
- srcfilename = argv[0]
- outfilename = 'output.txt'
- if len(argv) > 1:
- outfilename = argv[1]
- # 이미지를 열고 -
- with Image.open(argv[0]) as im:
- width, height = im.size
- px = im.load()
- print(f'image size {width} x {height}')
- outfile = open(outfilename,'w')
- for y in range(height):
- for x in range(width):
- hexcolor = '#%02x%02x%02x' % px[x, y]
- outfile.write(f'{x},{y},{hexcolor}\n')
- outfile.close()
- if __name__ == "__main__":
- main(sys.argv[1:])
Advertisement