Spaces:
Sleeping
Sleeping
| """High-level image processing entry points (no UI dependencies).""" | |
| from __future__ import annotations | |
| import os | |
| import shutil | |
| import tempfile | |
| from image_resizer.models import ImageItem, ProcessResult | |
| from image_resizer.pipeline import process_and_zip | |
| def process_uploaded_images( | |
| files, | |
| fmt: str, | |
| w: int, | |
| h: int, | |
| use_default: bool = False, | |
| ) -> ProcessResult: | |
| """Copy uploaded files to a temp dir and process them.""" | |
| tmp = tempfile.mkdtemp() | |
| data: list[ImageItem] = [] | |
| for f in files: | |
| src = str(f) | |
| dst = os.path.join(tmp, os.path.basename(src)) | |
| shutil.copyfile(src, dst) | |
| data.append({ | |
| "url": dst, | |
| "name": os.path.splitext(os.path.basename(dst))[0], | |
| }) | |
| return process_and_zip(data, fmt, w, h, use_default=use_default) | |
| def process_single_url_image( | |
| url: str, | |
| fmt: str, | |
| w: int, | |
| h: int, | |
| use_default: bool = False, | |
| ) -> ProcessResult: | |
| """Process a single image URL.""" | |
| if not url.strip(): | |
| return ProcessResult([], None, "No URL provided", None) | |
| return process_and_zip( | |
| [{"url": url.strip(), "name": "single"}], | |
| fmt, w, h, | |
| use_default=use_default, | |
| ) | |