summaryrefslogtreecommitdiffstats
path: root/g4f/image.py
diff options
context:
space:
mode:
authorHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-11 03:33:02 +0100
committerHeiner Lohaus <hlohaus@users.noreply.github.com>2024-02-11 03:33:02 +0100
commitdaf2b6ac3bf607f4f2e279545125c7559edb450e (patch)
treed3d4e1b48587682890817a18295a8eda76e7afed /g4f/image.py
parentAdd GPT 4 support in You, Add camera input, Enable logging on debug in GUI, Don't load expired cookies (diff)
downloadgpt4free-daf2b6ac3bf607f4f2e279545125c7559edb450e.tar
gpt4free-daf2b6ac3bf607f4f2e279545125c7559edb450e.tar.gz
gpt4free-daf2b6ac3bf607f4f2e279545125c7559edb450e.tar.bz2
gpt4free-daf2b6ac3bf607f4f2e279545125c7559edb450e.tar.lz
gpt4free-daf2b6ac3bf607f4f2e279545125c7559edb450e.tar.xz
gpt4free-daf2b6ac3bf607f4f2e279545125c7559edb450e.tar.zst
gpt4free-daf2b6ac3bf607f4f2e279545125c7559edb450e.zip
Diffstat (limited to 'g4f/image.py')
-rw-r--r--g4f/image.py28
1 files changed, 15 insertions, 13 deletions
diff --git a/g4f/image.py b/g4f/image.py
index 31c3d577..93922c2e 100644
--- a/g4f/image.py
+++ b/g4f/image.py
@@ -137,12 +137,12 @@ def get_orientation(image: Image) -> int:
if orientation is not None:
return orientation
-def process_image(img: Image, new_width: int, new_height: int) -> Image:
+def process_image(image: Image, new_width: int, new_height: int) -> Image:
"""
Processes the given image by adjusting its orientation and resizing it.
Args:
- img (Image): The image to process.
+ image (Image): The image to process.
new_width (int): The new width of the image.
new_height (int): The new height of the image.
@@ -150,25 +150,27 @@ def process_image(img: Image, new_width: int, new_height: int) -> Image:
Image: The processed image.
"""
# Fix orientation
- orientation = get_orientation(img)
+ orientation = get_orientation(image)
if orientation:
if orientation > 4:
- img = img.transpose(FLIP_LEFT_RIGHT)
+ image = image.transpose(FLIP_LEFT_RIGHT)
if orientation in [3, 4]:
- img = img.transpose(ROTATE_180)
+ image = image.transpose(ROTATE_180)
if orientation in [5, 6]:
- img = img.transpose(ROTATE_270)
+ image = image.transpose(ROTATE_270)
if orientation in [7, 8]:
- img = img.transpose(ROTATE_90)
+ image = image.transpose(ROTATE_90)
# Resize image
- img.thumbnail((new_width, new_height))
+ image.thumbnail((new_width, new_height))
# Remove transparency
- if img.mode == "RGBA":
- img.load()
- white = new_image('RGB', img.size, (255, 255, 255))
- white.paste(img, mask=img.split()[-1])
+ if image.mode == "RGBA":
+ image.load()
+ white = new_image('RGB', image.size, (255, 255, 255))
+ white.paste(image, mask=image.split()[-1])
return white
- return img
+ elif image.mode != "RGB":
+ image = image.convert("RGB")
+ return image
def to_base64_jpg(image: Image, compression_rate: float) -> str:
"""