Created
September 26, 2025 15:36
-
-
Save shotadft/be6eac68b1c5d936bba36988637a6f2e to your computer and use it in GitHub Desktop.
バイナリをBMP形式の画像に変換するだけの関数。https://x.com/McDonaldsJapan/status/1971530192137990518 解読の為に作った
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 characters
| from PIL import Image | |
| import numpy as np | |
| def binary_to_image(bin: str, width: int, height: int): | |
| data = np.array([int(b) * 0xFF for b in bin], dtype=np.uint8) | |
| out = np.pad(data, (0, (width * height) - len(data)), 'constant') | |
| img = Image.fromarray(out.reshape((height, width))) | |
| return img |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment