Jarvis-Brain 0.1.11.10__tar.gz → 0.1.11.11__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {jarvis_brain-0.1.11.10 → jarvis_brain-0.1.11.11}/PKG-INFO +1 -1
- {jarvis_brain-0.1.11.10 → jarvis_brain-0.1.11.11}/pyproject.toml +1 -1
- {jarvis_brain-0.1.11.10 → jarvis_brain-0.1.11.11}/tools/tools.py +67 -27
- {jarvis_brain-0.1.11.10 → jarvis_brain-0.1.11.11}/.gitignore +0 -0
- {jarvis_brain-0.1.11.10 → jarvis_brain-0.1.11.11}/README.md +0 -0
- {jarvis_brain-0.1.11.10 → jarvis_brain-0.1.11.11}/mcp_tools/__init__.py +0 -0
- {jarvis_brain-0.1.11.10 → jarvis_brain-0.1.11.11}/mcp_tools/dp_tools.py +0 -0
- {jarvis_brain-0.1.11.10 → jarvis_brain-0.1.11.11}/mcp_tools/main.py +0 -0
- {jarvis_brain-0.1.11.10 → jarvis_brain-0.1.11.11}/tools/__init__.py +0 -0
- {jarvis_brain-0.1.11.10 → jarvis_brain-0.1.11.11}/tools/browser_manager.py +0 -0
- {jarvis_brain-0.1.11.10 → jarvis_brain-0.1.11.11}/tools/browser_proxy.py +0 -0
- {jarvis_brain-0.1.11.10 → jarvis_brain-0.1.11.11}/uv.lock +0 -0
|
@@ -212,62 +212,102 @@ def btyes2Base64Img(target_byte):
|
|
|
212
212
|
return "data:image/png;base64," + base64.b64encode(target_byte).decode()
|
|
213
213
|
|
|
214
214
|
|
|
215
|
-
def compress_image_bytes(input_bytes, target_size_mb=1):
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
# def compress_image_bytes(input_bytes, target_size_mb=1):
|
|
216
|
+
# """
|
|
217
|
+
# 压缩图片字节数据到目标大小
|
|
218
|
+
#
|
|
219
|
+
# 参数:
|
|
220
|
+
# input_bytes: 输入图片的字节数据
|
|
221
|
+
# target_size_mb: 目标大小(MB),默认1MB
|
|
222
|
+
#
|
|
223
|
+
# 返回:
|
|
224
|
+
# 压缩后的图片字节数据
|
|
225
|
+
# """
|
|
226
|
+
# target_size = target_size_mb * 1024 * 1024 # 转换为字节
|
|
227
|
+
#
|
|
228
|
+
# # 从字节数据打开图片
|
|
229
|
+
# img = Image.open(io.BytesIO(input_bytes))
|
|
230
|
+
#
|
|
231
|
+
# # 如果是PNG或其他格式,转换为RGB
|
|
232
|
+
# if img.mode in ('RGBA', 'LA', 'P'):
|
|
233
|
+
# img = img.convert('RGB')
|
|
234
|
+
#
|
|
235
|
+
# # 初始质量设置
|
|
236
|
+
# quality = 95
|
|
237
|
+
#
|
|
238
|
+
# # 先尝试压缩
|
|
239
|
+
# output_buffer = io.BytesIO()
|
|
240
|
+
# img.save(output_buffer, 'JPEG', quality=quality, optimize=True)
|
|
241
|
+
# output_bytes = output_buffer.getvalue()
|
|
242
|
+
#
|
|
243
|
+
# # 如果文件仍然太大,逐步降低质量
|
|
244
|
+
# while len(output_bytes) > target_size and quality > 10:
|
|
245
|
+
# quality -= 5
|
|
246
|
+
# output_buffer = io.BytesIO()
|
|
247
|
+
# img.save(output_buffer, 'JPEG', quality=quality, optimize=True)
|
|
248
|
+
# output_bytes = output_buffer.getvalue()
|
|
249
|
+
#
|
|
250
|
+
# # 如果降低质量还不够,尝试缩小尺寸
|
|
251
|
+
# if len(output_bytes) > target_size:
|
|
252
|
+
# width, height = img.size
|
|
253
|
+
#
|
|
254
|
+
# while len(output_bytes) > target_size and quality > 10:
|
|
255
|
+
# # 缩小10%
|
|
256
|
+
# width = int(width * 0.9)
|
|
257
|
+
# height = int(height * 0.9)
|
|
258
|
+
# img_resized = img.resize((width, height), Image.Resampling.LANCZOS)
|
|
259
|
+
# output_buffer = io.BytesIO()
|
|
260
|
+
# img_resized.save(output_buffer, 'JPEG', quality=quality, optimize=True)
|
|
261
|
+
# output_bytes = output_buffer.getvalue()
|
|
262
|
+
#
|
|
263
|
+
# final_size = len(output_bytes) / (1024 * 1024)
|
|
264
|
+
# # print(f"压缩完成!")
|
|
265
|
+
# # print(f"原始大小: {len(input_bytes) / (1024 * 1024):.2f}MB")
|
|
266
|
+
# # print(f"压缩后大小: {final_size:.2f}MB")
|
|
267
|
+
# # print(f"最终质量: {quality}")
|
|
268
|
+
#
|
|
269
|
+
# return output_bytes
|
|
270
|
+
#
|
|
218
271
|
|
|
219
|
-
参数:
|
|
220
|
-
input_bytes: 输入图片的字节数据
|
|
221
|
-
target_size_mb: 目标大小(MB),默认1MB
|
|
222
272
|
|
|
223
|
-
返回:
|
|
224
|
-
压缩后的图片字节数据
|
|
225
|
-
"""
|
|
226
|
-
target_size = target_size_mb * 1024 * 1024 # 转换为字节
|
|
227
273
|
|
|
228
|
-
|
|
229
|
-
|
|
274
|
+
def compress_image_bytes(input_bytes, target_size_mb=1):
|
|
275
|
+
target_size = target_size_mb * 1024 * 1024
|
|
230
276
|
|
|
231
|
-
|
|
277
|
+
img = Image.open(io.BytesIO(input_bytes))
|
|
232
278
|
if img.mode in ('RGBA', 'LA', 'P'):
|
|
233
279
|
img = img.convert('RGB')
|
|
234
280
|
|
|
235
|
-
# 初始质量设置
|
|
236
281
|
quality = 95
|
|
237
|
-
|
|
238
|
-
# 先尝试压缩
|
|
239
282
|
output_buffer = io.BytesIO()
|
|
240
283
|
img.save(output_buffer, 'JPEG', quality=quality, optimize=True)
|
|
241
284
|
output_bytes = output_buffer.getvalue()
|
|
242
285
|
|
|
243
|
-
#
|
|
286
|
+
# 1. 优先降低质量
|
|
244
287
|
while len(output_bytes) > target_size and quality > 10:
|
|
245
288
|
quality -= 5
|
|
246
289
|
output_buffer = io.BytesIO()
|
|
247
290
|
img.save(output_buffer, 'JPEG', quality=quality, optimize=True)
|
|
248
291
|
output_bytes = output_buffer.getvalue()
|
|
249
292
|
|
|
250
|
-
#
|
|
293
|
+
# 2. 如果质量降到底(10)还是太大,开始缩小尺寸
|
|
251
294
|
if len(output_bytes) > target_size:
|
|
252
295
|
width, height = img.size
|
|
253
296
|
|
|
254
|
-
|
|
255
|
-
|
|
297
|
+
# 修改点:这里去掉了 'and quality > 10',改为防止图片缩得太小 (width > 100)
|
|
298
|
+
while len(output_bytes) > target_size and width > 100:
|
|
256
299
|
width = int(width * 0.9)
|
|
257
300
|
height = int(height * 0.9)
|
|
301
|
+
|
|
302
|
+
# 重新调整尺寸
|
|
258
303
|
img_resized = img.resize((width, height), Image.Resampling.LANCZOS)
|
|
304
|
+
|
|
259
305
|
output_buffer = io.BytesIO()
|
|
306
|
+
# 注意:这里继续使用当前的最低质量(10)进行保存,或者你可以适当回调一点质量
|
|
260
307
|
img_resized.save(output_buffer, 'JPEG', quality=quality, optimize=True)
|
|
261
308
|
output_bytes = output_buffer.getvalue()
|
|
262
309
|
|
|
263
|
-
final_size = len(output_bytes) / (1024 * 1024)
|
|
264
|
-
# print(f"压缩完成!")
|
|
265
|
-
# print(f"原始大小: {len(input_bytes) / (1024 * 1024):.2f}MB")
|
|
266
|
-
# print(f"压缩后大小: {final_size:.2f}MB")
|
|
267
|
-
# print(f"最终质量: {quality}")
|
|
268
|
-
|
|
269
310
|
return output_bytes
|
|
270
|
-
|
|
271
311
|
# todo: 大致盘一下各种判定的逻辑【以下的所有压缩比之间的差距均取“绝对值”】
|
|
272
312
|
# 1. 如果requests、无头、有头获取到的压缩比之间从差距都在15%以内,则认定该页面是静态页面,此时优先使用requests请求
|
|
273
313
|
# 2. 如果requests的status_code为特定的412,或者521,则判定是瑞数和jsl。[此时还有一个特点:requests的压缩比会与其他两种方式获取到的压缩比差距非常大(一两千的那种)]
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|