OS_ROM_URL = 'http://www.bbcmicrogames.com/roms/os12.zip' import requests # downloading the zipfile from io import BytesIO # treating a bytes object as file import zipfile # parsing the zipfile # Fetch the ROM and check that the GET succeeded os_rom_zip_req = requests.get(OS_ROM_URL) assert os_rom_zip_req.status_code == 200 # Parse the body as a zip file os_rom_zip = zipfile.ZipFile(BytesIO(os_rom_zip_req.content)) print('Archive contents: ' + ','.join(os_rom_zip.namelist())) assert len(os_rom_zip.filelist) == 1 font_table = os_rom_zip.read(os_rom_zip.filelist[0])[:0x300] import numpy as np from bitarray import bitarray font_table_array = bitarray(endian='big') font_table_array.frombytes(font_table) font = np.array(font_table_array.tolist()).reshape((-1, 8)) n_chars = font.shape[0] // 8 print('Number of characters: {0}'.format(n_chars)) %matplotlib inline from matplotlib.pyplot import * imshow(font[:8*3, :], interpolation='none', cmap='gray') char_arrays = np.split(font, n_chars) # check that we've split correctly imshow(char_arrays[20], interpolation='none', cmap='gray') font_image = np.vstack(tuple( np.hstack(row).reshape((8, -1)) for row in np.array(char_arrays).reshape((-1, 16, 8, 8)) )) print('Generated font image of shape: ' + 'x'.join(str(x) for x in font_image.shape)) imshow(font_image, cmap='gray', interpolation='none') import json from imgurpython import ImgurClient imgur_creds = json.load(open('imgur-credentials.json')) imgur_client = ImgurClient(imgur_creds['clientId'], imgur_creds['clientSecret']) import tempfile from PIL import Image with tempfile.NamedTemporaryFile(suffix='.png') as tf: Image.fromarray(np.where(font_image, 255, 0).astype(np.uint8)).save(tf.name) upload_result = imgur_client.upload_from_path(tf.name) print('Image uploaded to: {0}'.format(upload_result['link'])) from IPython.display import Image Image(upload_result['link'])