返回提交历史
Modified
g4f/gui/client/js/chat.v1.js
+1
-2
Modified
g4f/image.py
+15
-13
XFEstudio/gpt4free
Fix convert image to jpg in Bing Fix display upload image in GUI
daf2b6ac
代码差异
2 个文件
+16
-15
@@ -677,7 +677,7 @@ observer.observe(message_input, { attributes: true });
677
677
}
678
678
document.getElementById("version_text").innerHTML = text
679
679
})()
680
for (el of [imageInput, cameraInput]) {
680
for (const el of [imageInput, cameraInput]) {
681
681
console.log(el.files);
682
682
el.addEventListener('click', async () => {
683
683
el.value = '';
@@ -690,7 +690,6 @@ for (el of [imageInput, cameraInput]) {
690
690
const reader = new FileReader();
691
691
reader.addEventListener('load', (event) => {
692
692
el.dataset.src = event.target.result;
693
console.log(el.dataset.src);
694
693
});
695
694
reader.readAsDataURL(el.files[0]);
696
695
}
@@ -137,12 +137,12 @@ def get_orientation(image: Image) -> int:
137
137
if orientation is not None:
138
138
return orientation
139
139
140
def process_image(img: Image, new_width: int, new_height: int) -> Image:
140
def process_image(image: Image, new_width: int, new_height: int) -> Image:
141
141
"""
142
142
Processes the given image by adjusting its orientation and resizing it.
143
143
144
144
Args:
145
img (Image): The image to process.
145
image (Image): The image to process.
146
146
new_width (int): The new width of the image.
147
147
new_height (int): The new height of the image.
148
148
@@ -150,25 +150,27 @@ def process_image(img: Image, new_width: int, new_height: int) -> Image:
150
150
Image: The processed image.
151
151
"""
152
152
# Fix orientation
153
orientation = get_orientation(img)
153
orientation = get_orientation(image)
154
154
if orientation:
155
155
if orientation > 4:
156
img = img.transpose(FLIP_LEFT_RIGHT)
156
image = image.transpose(FLIP_LEFT_RIGHT)
157
157
if orientation in [3, 4]:
158
img = img.transpose(ROTATE_180)
158
image = image.transpose(ROTATE_180)
159
159
if orientation in [5, 6]:
160
img = img.transpose(ROTATE_270)
160
image = image.transpose(ROTATE_270)
161
161
if orientation in [7, 8]:
162
img = img.transpose(ROTATE_90)
162
image = image.transpose(ROTATE_90)
163
163
# Resize image
164
img.thumbnail((new_width, new_height))
164
image.thumbnail((new_width, new_height))
165
165
# Remove transparency
166
if img.mode == "RGBA":
167
img.load()
168
white = new_image('RGB', img.size, (255, 255, 255))
169
white.paste(img, mask=img.split()[-1])
166
if image.mode == "RGBA":
167
image.load()
168
white = new_image('RGB', image.size, (255, 255, 255))
169
white.paste(image, mask=image.split()[-1])
170
170
return white
171
return img
171
elif image.mode != "RGB":
172
image = image.convert("RGB")
173
return image
172
174
173
175
def to_base64_jpg(image: Image, compression_rate: float) -> str:
174
176
"""