summaryrefslogtreecommitdiff
path: root/utils/utils_img
diff options
context:
space:
mode:
authorKyomotoi <[email protected]>2020-11-07 14:49:51 +0800
committerKyomotoi <[email protected]>2020-11-07 14:49:51 +0800
commitc9074b24b98efe18096256ab680535f50691f67d (patch)
treefb912e4506e478d3d61e89b2824fc83d69eae7cd /utils/utils_img
parent85517a82b9f787ed7c3008655c8dc04d8e6f0a30 (diff)
downloadATRI-c9074b24b98efe18096256ab680535f50691f67d.tar.gz
ATRI-c9074b24b98efe18096256ab680535f50691f67d.tar.bz2
ATRI-c9074b24b98efe18096256ab680535f50691f67d.zip
[Upload]
Diffstat (limited to 'utils/utils_img')
-rw-r--r--utils/utils_img/__init__.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/utils/utils_img/__init__.py b/utils/utils_img/__init__.py
index 196e138..7b79146 100644
--- a/utils/utils_img/__init__.py
+++ b/utils/utils_img/__init__.py
@@ -1,8 +1,9 @@
#!/usr/bin/env python3
# -*- encoding: utf-8 -*-
+
'''
@File : __init__.py
-@Time : 2020/10/11 14:40:17
+@Time : 2020/11/07 14:17:37
@Author : Kyomotoi
@Contact : [email protected]
@Github : https://github.com/Kyomotoi
@@ -13,11 +14,10 @@ __author__ = 'kyomotoi'
import os
import string
import aiohttp
-import PIL.Image as Image
from pathlib import Path
from random import sample
-from PIL import Image
+import PIL.Image as Image
from PIL import ImageFile
async def aio_download_pics(url) -> str:
@@ -30,9 +30,9 @@ async def aio_download_pics(url) -> str:
path = os.path.abspath(path)
img_key = ''.join(sample(string.ascii_letters + string.digits, 16))
img = path + f'\\{img_key}.png'
- async with aiohttp.ClientSession() as session:
- async with session.get(url) as response:
- pic = await response.read() #以Bytes方式读入非文字
+ async with aiohttp.ClientSession() as session:
+ async with session.get(url) as response:
+ pic = await response.read() #以Bytes方式读入非文字
with open(img, mode='wb') as f:# 写入文件
f.write(pic)
f.close()
@@ -47,7 +47,7 @@ def compress_image(outfile: str, kb=400, quality=85, k=0.9) -> str:
o_size = os.path.getsize(outfile) // 1024
if o_size <= kb:
return outfile
-
+
ImageFile.LOAD_TRUNCATED_IMAGES = True # type: ignore
while o_size > kb:
im = Image.open(outfile)