fix icc_profile
This commit is contained in:
@@ -135,31 +135,27 @@ def numpy_to_bytes(image_numpy: np.ndarray, ext: str) -> bytes:
|
||||
return image_bytes
|
||||
|
||||
|
||||
def pil_to_bytes(pil_img, ext: str, quality: int = 95, exif_infos={}) -> bytes:
|
||||
def pil_to_bytes(pil_img, ext: str, quality: int = 95, infos={}) -> bytes:
|
||||
with io.BytesIO() as output:
|
||||
kwargs = {k: v for k, v in exif_infos.items() if v is not None}
|
||||
if ext == "png" and "parameters" in kwargs:
|
||||
kwargs = {k: v for k, v in infos.items() if v is not None}
|
||||
if ext == 'jpg':
|
||||
ext = 'jpeg'
|
||||
if "png" == ext.lower() and "parameters" in kwargs:
|
||||
pnginfo_data = PngImagePlugin.PngInfo()
|
||||
pnginfo_data.add_text("parameters", kwargs["parameters"])
|
||||
kwargs["pnginfo"] = pnginfo_data
|
||||
|
||||
pil_img.save(
|
||||
output,
|
||||
format=ext,
|
||||
quality=quality,
|
||||
**kwargs,
|
||||
)
|
||||
pil_img.save(output, format=ext, quality=quality, **kwargs)
|
||||
image_bytes = output.getvalue()
|
||||
return image_bytes
|
||||
|
||||
|
||||
def load_img(img_bytes, gray: bool = False, return_exif: bool = False):
|
||||
def load_img(img_bytes, gray: bool = False, return_info: bool = False):
|
||||
alpha_channel = None
|
||||
image = Image.open(io.BytesIO(img_bytes))
|
||||
|
||||
if return_exif:
|
||||
info = image.info or {}
|
||||
exif_infos = {"exif": image.getexif(), "parameters": info.get("parameters")}
|
||||
if return_info:
|
||||
infos = image.info
|
||||
|
||||
try:
|
||||
image = ImageOps.exif_transpose(image)
|
||||
@@ -178,8 +174,8 @@ def load_img(img_bytes, gray: bool = False, return_exif: bool = False):
|
||||
image = image.convert("RGB")
|
||||
np_img = np.array(image)
|
||||
|
||||
if return_exif:
|
||||
return np_img, alpha_channel, exif_infos
|
||||
if return_info:
|
||||
return np_img, alpha_channel, infos
|
||||
return np_img, alpha_channel
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user