Skip to content

Instantly share code, notes, and snippets.

@shotadft
Created September 26, 2025 15:36
Show Gist options
  • Select an option

  • Save shotadft/be6eac68b1c5d936bba36988637a6f2e to your computer and use it in GitHub Desktop.

Select an option

Save shotadft/be6eac68b1c5d936bba36988637a6f2e to your computer and use it in GitHub Desktop.
バイナリをBMP形式の画像に変換するだけの関数。https://x.com/McDonaldsJapan/status/1971530192137990518 解読の為に作った
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