Created
March 25, 2023 02:01
-
-
Save KTibow/07b1f6a60b3a9bb8b657614aafd96c61 to your computer and use it in GitHub Desktop.
Revisions
-
KTibow created this gist
Mar 25, 2023 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,28 @@ from PIL import Image, ImageOps image = Image.open("snapshot.jpg") width, height = image.size if width > 178 or height > 128: image.thumbnail((178, 128)) image = ImageOps.pad(image, (178, 128), color=(255, 255, 255)) image = image.convert("1") width, height = 178, 128 binary_data = bytes([width, height]) for y in range(height): cur_byte = 0 cur_bit = 0 for x in range(width): if image.getpixel((x, y)) == 0: cur_byte += pow(2, cur_bit) cur_bit += 1 if cur_bit == 8: binary_data += bytes([cur_byte]) cur_byte = 0 cur_bit = 0 binary_data += bytes([cur_byte]) with open("out.rgf", "wb") as out: out.write(binary_data)