From 427e20cd212a7340f8cb15a45c731673b9ff43c0 Mon Sep 17 00:00:00 2001 From: BillXuce Date: Fri, 7 Feb 2020 10:23:52 +0800 Subject: [PATCH] =?UTF-8?q?#55=20=E4=B8=8B=E8=BD=BD=E5=88=B0=E7=9A=84?= =?UTF-8?q?=E9=9D=9Ejpg=E6=A0=BC=E5=BC=8F=E5=9B=BE=E7=89=87=E7=BB=8F?= =?UTF-8?q?=E8=BD=AC=E6=8D=A2=E4=B9=9F=E5=8F=AF=E4=BB=A5=E6=AD=A3=E5=B8=B8?= =?UTF-8?q?=E7=94=9F=E6=88=90pdf=E4=BA=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wqxtDownloader.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/wqxtDownloader.py b/wqxtDownloader.py index 153744b..aef7238 100644 --- a/wqxtDownloader.py +++ b/wqxtDownloader.py @@ -7,7 +7,10 @@ import logging import jwt import socket + from urllib import error +from io import BytesIO +from PIL import Image class wqxtDownloader(): fileExt = ".jpg"; @@ -226,13 +229,24 @@ def downloadImage( self, url, path ): raise InvalidPictureError if len( data )<=5: raise InvalidPictureError - f = open(path,"wb") - f.write(data) - f.close() + if data[:4] == b'\xff\xd8\xff\xe0': # 是不是jpg文件 + f = open(path,"wb") + f.write(data) + f.close() + else: + self.img_converter(data, path) return True; else: return False; + def img_converter(self, in_img, path): + img = BytesIO(in_img) + origin_img = Image.open(img) + jpg_img = origin_img.convert('RGB') + jpg_img.save(path) + img.close() + del img + def getImgPath( self, page ): fileExt = self.fileExt; folder = self.folder;