mirror of
https://github.com/xtekky/gpt4free.git
synced 2024-11-27 05:25:33 +03:00
Fix convert image to jpg in Bing
Fix display upload image in GUI
This commit is contained in:
parent
6c422b2965
commit
daf2b6ac3b
@ -677,7 +677,7 @@ observer.observe(message_input, { attributes: true });
|
|||||||
}
|
}
|
||||||
document.getElementById("version_text").innerHTML = text
|
document.getElementById("version_text").innerHTML = text
|
||||||
})()
|
})()
|
||||||
for (el of [imageInput, cameraInput]) {
|
for (const el of [imageInput, cameraInput]) {
|
||||||
console.log(el.files);
|
console.log(el.files);
|
||||||
el.addEventListener('click', async () => {
|
el.addEventListener('click', async () => {
|
||||||
el.value = '';
|
el.value = '';
|
||||||
@ -690,7 +690,6 @@ for (el of [imageInput, cameraInput]) {
|
|||||||
const reader = new FileReader();
|
const reader = new FileReader();
|
||||||
reader.addEventListener('load', (event) => {
|
reader.addEventListener('load', (event) => {
|
||||||
el.dataset.src = event.target.result;
|
el.dataset.src = event.target.result;
|
||||||
console.log(el.dataset.src);
|
|
||||||
});
|
});
|
||||||
reader.readAsDataURL(el.files[0]);
|
reader.readAsDataURL(el.files[0]);
|
||||||
}
|
}
|
||||||
|
28
g4f/image.py
28
g4f/image.py
@ -137,12 +137,12 @@ def get_orientation(image: Image) -> int:
|
|||||||
if orientation is not None:
|
if orientation is not None:
|
||||||
return orientation
|
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.
|
Processes the given image by adjusting its orientation and resizing it.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
img (Image): The image to process.
|
image (Image): The image to process.
|
||||||
new_width (int): The new width of the image.
|
new_width (int): The new width of the image.
|
||||||
new_height (int): The new height 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.
|
Image: The processed image.
|
||||||
"""
|
"""
|
||||||
# Fix orientation
|
# Fix orientation
|
||||||
orientation = get_orientation(img)
|
orientation = get_orientation(image)
|
||||||
if orientation:
|
if orientation:
|
||||||
if orientation > 4:
|
if orientation > 4:
|
||||||
img = img.transpose(FLIP_LEFT_RIGHT)
|
image = image.transpose(FLIP_LEFT_RIGHT)
|
||||||
if orientation in [3, 4]:
|
if orientation in [3, 4]:
|
||||||
img = img.transpose(ROTATE_180)
|
image = image.transpose(ROTATE_180)
|
||||||
if orientation in [5, 6]:
|
if orientation in [5, 6]:
|
||||||
img = img.transpose(ROTATE_270)
|
image = image.transpose(ROTATE_270)
|
||||||
if orientation in [7, 8]:
|
if orientation in [7, 8]:
|
||||||
img = img.transpose(ROTATE_90)
|
image = image.transpose(ROTATE_90)
|
||||||
# Resize image
|
# Resize image
|
||||||
img.thumbnail((new_width, new_height))
|
image.thumbnail((new_width, new_height))
|
||||||
# Remove transparency
|
# Remove transparency
|
||||||
if img.mode == "RGBA":
|
if image.mode == "RGBA":
|
||||||
img.load()
|
image.load()
|
||||||
white = new_image('RGB', img.size, (255, 255, 255))
|
white = new_image('RGB', image.size, (255, 255, 255))
|
||||||
white.paste(img, mask=img.split()[-1])
|
white.paste(image, mask=image.split()[-1])
|
||||||
return white
|
return white
|
||||||
return img
|
elif image.mode != "RGB":
|
||||||
|
image = image.convert("RGB")
|
||||||
|
return image
|
||||||
|
|
||||||
def to_base64_jpg(image: Image, compression_rate: float) -> str:
|
def to_base64_jpg(image: Image, compression_rate: float) -> str:
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user