Spaces:
Running
Running
| from PIL import Image, ImageDraw, ImageFont | |
| import base64 | |
| from io import BytesIO | |
| def split_image(image: Image.Image, num_chunks: int) -> list: | |
| width, height = image.size | |
| chunk_height = height // num_chunks | |
| chunks = [] | |
| for i in range(num_chunks): | |
| top = i * chunk_height | |
| bottom = (i + 1) * chunk_height if i < num_chunks - 1 else height | |
| chunks.append(image.crop((0, top, width, bottom))) | |
| return chunks | |
| def encode_image_to_html(image: Image.Image) -> str: | |
| buffered = BytesIO() | |
| image.save(buffered, format="PNG") | |
| encoded = base64.b64encode(buffered.getvalue()).decode() | |
| return f""" | |
| <div style="height:500px; overflow-y:auto; border:1px solid #ccc;"> | |
| <img src="data:image/png;base64,{encoded}" style="width:100%;" /> | |
| </div> | |
| """ |