image random rotate fix
Browse files
server.py
CHANGED
|
@@ -12,7 +12,7 @@ import tempfile
|
|
| 12 |
from fastapi import FastAPI, File, Form, Request, UploadFile
|
| 13 |
from fastapi.responses import JSONResponse, StreamingResponse, Response
|
| 14 |
from fastapi.staticfiles import StaticFiles
|
| 15 |
-
from PIL import Image
|
| 16 |
import numpy as np
|
| 17 |
import cv2
|
| 18 |
|
|
@@ -231,7 +231,7 @@ async def compress(request: Request):
|
|
| 231 |
return JSONResponse({"error": "No image provided"}, status_code=400)
|
| 232 |
try:
|
| 233 |
raw_bytes = await upload.read()
|
| 234 |
-
src = Image.open(io.BytesIO(raw_bytes))
|
| 235 |
img = src.convert("RGBA") if PBC3._has_alpha(src) else src.convert("RGB")
|
| 236 |
except Exception as exc:
|
| 237 |
return JSONResponse({"error": f"Could not read image: {exc}"}, status_code=400)
|
|
@@ -297,7 +297,7 @@ async def compress(request: Request):
|
|
| 297 |
@app.post("/api/stream_compress")
|
| 298 |
async def stream_compress(image: UploadFile = File(...), downsample_initialize: str = Form("false")):
|
| 299 |
raw = await image.read()
|
| 300 |
-
img = Image.open(io.BytesIO(raw)).convert("RGB")
|
| 301 |
|
| 302 |
def gen():
|
| 303 |
for ev in PBC3.compress_stream(
|
|
@@ -742,7 +742,7 @@ def sweeps_codec_baseline(mp: str = "", codec: str = "jpeg"):
|
|
| 742 |
@app.post("/api/match_codec")
|
| 743 |
async def match_codec(image: UploadFile = File(...), codec: str = Form("jpeg"), target_bpp: float = Form(...)):
|
| 744 |
try:
|
| 745 |
-
img = Image.open(io.BytesIO(await image.read())).convert("RGB")
|
| 746 |
except Exception as exc:
|
| 747 |
return JSONResponse({"error": f"Could not read image: {exc}"}, status_code=400)
|
| 748 |
fmt = "JPEG" if codec.lower() == "jpeg" else "AVIF"
|
|
@@ -930,7 +930,7 @@ async def animate(file: UploadFile = File(...), original: UploadFile = File(None
|
|
| 930 |
orig_img = None
|
| 931 |
if original is not None:
|
| 932 |
try:
|
| 933 |
-
orig_img = Image.open(io.BytesIO(await original.read())).convert("RGB")
|
| 934 |
except Exception:
|
| 935 |
orig_img = None
|
| 936 |
fd, base = tempfile.mkstemp(suffix=".mp4")
|
|
|
|
| 12 |
from fastapi import FastAPI, File, Form, Request, UploadFile
|
| 13 |
from fastapi.responses import JSONResponse, StreamingResponse, Response
|
| 14 |
from fastapi.staticfiles import StaticFiles
|
| 15 |
+
from PIL import Image, ImageOps
|
| 16 |
import numpy as np
|
| 17 |
import cv2
|
| 18 |
|
|
|
|
| 231 |
return JSONResponse({"error": "No image provided"}, status_code=400)
|
| 232 |
try:
|
| 233 |
raw_bytes = await upload.read()
|
| 234 |
+
src = ImageOps.exif_transpose(Image.open(io.BytesIO(raw_bytes)))
|
| 235 |
img = src.convert("RGBA") if PBC3._has_alpha(src) else src.convert("RGB")
|
| 236 |
except Exception as exc:
|
| 237 |
return JSONResponse({"error": f"Could not read image: {exc}"}, status_code=400)
|
|
|
|
| 297 |
@app.post("/api/stream_compress")
|
| 298 |
async def stream_compress(image: UploadFile = File(...), downsample_initialize: str = Form("false")):
|
| 299 |
raw = await image.read()
|
| 300 |
+
img = ImageOps.exif_transpose(Image.open(io.BytesIO(raw))).convert("RGB")
|
| 301 |
|
| 302 |
def gen():
|
| 303 |
for ev in PBC3.compress_stream(
|
|
|
|
| 742 |
@app.post("/api/match_codec")
|
| 743 |
async def match_codec(image: UploadFile = File(...), codec: str = Form("jpeg"), target_bpp: float = Form(...)):
|
| 744 |
try:
|
| 745 |
+
img = ImageOps.exif_transpose(Image.open(io.BytesIO(await image.read()))).convert("RGB")
|
| 746 |
except Exception as exc:
|
| 747 |
return JSONResponse({"error": f"Could not read image: {exc}"}, status_code=400)
|
| 748 |
fmt = "JPEG" if codec.lower() == "jpeg" else "AVIF"
|
|
|
|
| 930 |
orig_img = None
|
| 931 |
if original is not None:
|
| 932 |
try:
|
| 933 |
+
orig_img = ImageOps.exif_transpose(Image.open(io.BytesIO(await original.read()))).convert("RGB")
|
| 934 |
except Exception:
|
| 935 |
orig_img = None
|
| 936 |
fd, base = tempfile.mkstemp(suffix=".mp4")
|