Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

Commit

Permalink
#55 下载到的非jpg格式图片经转换也可以正常生成pdf了
Browse files Browse the repository at this point in the history
  • Loading branch information
BillXuce committed Feb 7, 2020
1 parent 186029e commit 427e20c
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions wqxtDownloader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 427e20c

Please sign in to comment.