Skip to content

Commit

Permalink
fix ext not found
Browse files Browse the repository at this point in the history
change chunk splitting to be all same size
  • Loading branch information
ArdaxHz committed Sep 30, 2024
1 parent d67946d commit 1d97d40
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions mupl/image_validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,23 +85,28 @@ def split_tall_images(image_name: "str", image_bytes: "bytes") -> "List[bytes]":
if height < 10_000:
return [image_bytes]

ext = ImageProcessorBase.get_image_format(image_bytes)
ext = ext.name.lower()
desired_max_chunk_height = 3000
min_chunk_height = 1500
initial_num_chunks = math.ceil(height / desired_max_chunk_height)
chunk_height = math.ceil(height / initial_num_chunks)
if chunk_height < min_chunk_height:
chunk_height = min_chunk_height
num_chunks = math.ceil(height / chunk_height)
else:
num_chunks = initial_num_chunks

max_height = 3000
num_chunks = math.ceil(height / max_height)
logger.info(f"Split {image_name} into {num_chunks} chunks.")
print(f"Split {image_name} into {num_chunks} chunks.")
for i in range(num_chunks):
left = 0
upper = i * max_height
upper = i * chunk_height
right = width
lower = min((i + 1) * max_height, height)
lower = min((i + 1) * chunk_height, height)
bbox = (left, upper, right, lower)
working_slice = image.crop(bbox)

img_byte_arr = io.BytesIO()
working_slice.save(img_byte_arr, format=ext)
working_slice.save(img_byte_arr, format=image.format)
img_byte_arr = img_byte_arr.getvalue()
split_image.append(img_byte_arr)

Expand Down

0 comments on commit 1d97d40

Please sign in to comment.