Skip to content

BytesIO support #53

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

Merged
merged 2 commits into from
Jun 15, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
rename argument
  • Loading branch information
FoamyGuy committed Jun 13, 2021
commit 483e72ac5681bb2456c993eef94d6cecf4d002a7
9 changes: 5 additions & 4 deletions adafruit_imageload/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_ImageLoad.git"


def load(filename, *, bitmap=None, palette=None):
def load(file_or_filename, *, bitmap=None, palette=None):
"""Load pixel values (indices or colors) into a bitmap and colors into a palette.

bitmap is the desired type. It must take width, height and color_depth in the constructor. It
Expand All @@ -39,11 +39,12 @@ def load(filename, *, bitmap=None, palette=None):
# meh, we tried
pass

file_or_filename = filename
if isinstance(file_or_filename, str):
file_or_filename = open(filename, "rb")
open_file = open(file_or_filename, "rb")
else:
open_file = file_or_filename

with file_or_filename as file:
with open_file as file:
header = file.read(3)
file.seek(0)
if header.startswith(b"BM"):
Expand Down