This commit is contained in:
caiwx86 2022-12-06 20:34:58 +08:00
parent 7cf795b660
commit a97acb7595
2 changed files with 33 additions and 24 deletions

View File

@ -3,7 +3,7 @@ from utils.entity.RouMan import comicEntity
if __name__ == '__main__': if __name__ == '__main__':
# os.environ["http_proxy"] = "http://127.0.0.1:7890" # os.environ["http_proxy"] = "http://127.0.0.1:7890"
# os.environ["https_proxy"] = "http://127.0.0.1:7890" # os.environ["https_proxy"] = "http://127.0.0.1:7890"
# url = "https://rm01.xyz/books/f08668a4-0cbc-488e-95a7-3c71de0c7a31/1" # url = "https://rm01.xyz/books/3700b70b-c5a9-4328-9ae3-cffda6a77339/15"
# comicEntity.comicChapter(url,scramble=True) # comicEntity.comicChapter(url,scramble=True)
# comicEntity.oneComic("https://rm01.xyz/books/c94f80c1-a673-4c74-bb5e-ad5ac7dd766b") # comicEntity.oneComic("https://rm01.xyz/books/c94f80c1-a673-4c74-bb5e-ad5ac7dd766b")
for x in range(0,20): for x in range(0,20):

View File

@ -53,8 +53,14 @@ class imageUtils:
split_path = os.path.join(baseDir,save_name_delesu+"split") split_path = os.path.join(baseDir,save_name_delesu+"split")
if image_su == "downloads": if image_su == "downloads":
return None return None
cls.splitimage(file_path,blocks,1,split_path) is_split = cls.splitimage(file_path,blocks,1,split_path)
cls.image_compose(split_path,blocks,1,save_file_path,blockHeight,width) if not is_split == None:
cls.image_compose(split_path,blocks,1,save_file_path,blockHeight,width)
else:
if os.path.exists(split_path):
shutil.rmtree(split_path)
if os.path.exists(file_path):
shutil.move(file_path, save_file_path)
#完成后清空 #完成后清空
return file_path return file_path
@ -62,27 +68,30 @@ class imageUtils:
def splitimage(cls,src,rownum,colnum,dstpath): def splitimage(cls,src,rownum,colnum,dstpath):
img=Image.open(src) img=Image.open(src)
w,h=img.size w,h=img.size
s=os.path.split(src) if rownum<= h and colnum<=w:
if dstpath=='': s=os.path.split(src)
dstpath = s[0] if dstpath=='':
if not os.path.exists(dstpath): dstpath = s[0]
os.makedirs(dstpath) if not os.path.exists(dstpath):
fn=s[1].split('.') os.makedirs(dstpath)
basename=fn[0] fn=s[1].split('.')
ext=fn[-1] basename=fn[0]
num=0 ext=fn[-1]
rowheight=h//rownum num=0
colwidth=w//colnum rowheight=h//rownum
for r in range(rownum): colwidth=w//colnum
for c in range(colnum): for r in range(rownum):
box=(c*colwidth,r*rowheight,(c+1)*colwidth,(r+1)*rowheight) for c in range(colnum):
count_image = "{:0>3d}".format(num) box=(c*colwidth,r*rowheight,(c+1)*colwidth,(r+1)*rowheight)
file_path = os.path.join(dstpath,str(count_image)+'.'+ext) count_image = "{:0>3d}".format(num)
print("file_path=",file_path) file_path = os.path.join(dstpath,str(count_image)+'.'+ext)
img.crop(box).save(file_path) print("file_path=",file_path)
num=num+1 img.crop(box).save(file_path)
img.close num=num+1
return src return "成功"
else:
print('不数!')
return None
@classmethod @classmethod
def image_compose(cls,src,row,column,save_path,image_height,image_width): def image_compose(cls,src,row,column,save_path,image_height,image_width):