Skip to content

BMP import/export #509

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
lanrat opened this issue Oct 6, 2019 · 3 comments
Open

BMP import/export #509

lanrat opened this issue Oct 6, 2019 · 3 comments

Comments

@lanrat
Copy link

lanrat commented Oct 6, 2019

Describe the feature you'd like
It would be great if the badge magic app could export and import bmp images

Additional context
The OEM app has this feature.

@adityastic
Copy link
Collaborator

Let me look what changes are required to read this binary

@benjaminbellamy
Copy link

benjaminbellamy commented Mar 7, 2025

I wrote that Python script to convert images to json that can be imported with the mobile app:

from PIL import Image
import json

def bmp_to_hex_list(image_path):
    image = Image.open(image_path).convert('1')
    image_width, image_height = image.size
    char_width = 8
    char_height = 11
    num_chars = image_width // char_width
    hex_data = []
    for col in range(num_chars):
        binary_str = ""
        for y in range(char_height):
            for x in range(char_width):
                bit = 1 if image.getpixel((col * char_width + x, y)) == 0 else 0
                binary_str += str(bit)
        hex_str = hex(int(binary_str, 2))[2:].zfill((char_width * char_height) // 4)
        hex_data.append(hex_str)
    return hex_data

badge={'messages':[{'text':bmp_to_hex_list('badge.bmp'),'flash':False,'marquee':False,'speed':'0x60','mode':'0x00','invert':False}]}

print(json.dumps(badge, indent=4))

@adityastic
Copy link
Collaborator

@benjaminbellamy thats wonderful. Would you like to add an import feature that can do the same in the app? Feel free to create a PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: No status
Development

No branches or pull requests

5 participants