Jarvis-Brain 0.1.11.9__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: Jarvis_Brain
3
- Version: 0.1.11.9
3
+ Version: 0.1.11.11
4
4
  Summary: Jarvis brain mcp
5
5
  Requires-Python: >=3.10
6
6
  Requires-Dist: beautifulsoup4
@@ -325,9 +325,9 @@ def register_get_screenshot(mcp: FastMCP, browser_manager):
325
325
  os.makedirs(html_source_code_local_save_path)
326
326
  timestamp = int(time.time() * 1000)
327
327
  # time.sleep(1)
328
- origin_png = target_tab.get_screenshot(as_bytes="png", full_page=True)
328
+ origin_png = target_tab.get_screenshot(as_bytes="jpg", full_page=True)
329
329
  compress_png = compress_image_bytes(origin_png, 0.5)
330
- image_path = os.path.join(html_source_code_local_save_path, f"{browser_port}_{tab_id}_{timestamp}.png")
330
+ image_path = os.path.join(html_source_code_local_save_path, f"{browser_port}_{tab_id}_{timestamp}.jpg")
331
331
  with open(image_path, "wb") as f:
332
332
  f.write(compress_png)
333
333
  return dp_mcp_message_pack(
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "Jarvis_Brain" # 别人下载时用的名字,必须在 PyPI 上唯一
3
- version = "0.1.11.9"
3
+ version = "0.1.11.11"
4
4
  description = "Jarvis brain mcp"
5
5
  dependencies = [
6
6
  "fastmcp",
@@ -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
- img = Image.open(io.BytesIO(input_bytes))
274
+ def compress_image_bytes(input_bytes, target_size_mb=1):
275
+ target_size = target_size_mb * 1024 * 1024
230
276
 
231
- # 如果是PNG或其他格式,转换为RGB
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
- while len(output_bytes) > target_size and quality > 10:
255
- # 缩小10%
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的压缩比会与其他两种方式获取到的压缩比差距非常大(一两千的那种)]