删除过时文件

This commit is contained in:
vincent 2023-08-20 12:47:18 +08:00
parent 5cceeeb16d
commit eb286c0a0e

View File

@ -1,58 +0,0 @@
from requester import Requester
from web_img import WebImg
from PIL import Image
import io
from web_img import WebImg
from requester import Requester
class ImgManager:
def __init__(self, img_url_list: list[str]):
self.img_url_list = img_url_list
self.img_list = self.__create_web_img_list()
def __create_web_img_list(self):
return [WebImg(self.task_name, url) for url in self.img_url_list]
def batch_fetch_images(self):
requester = Requester()
requester.batch_fetch_images_to_img_obj_list(self.img_list)
def concatenate_images_vertically(self):
"""
垂直拼接长图片
"""
try:
# 计算拼接后的长图宽度和总高度
max_width = max(
Image.open(io.BytesIO(web_img.data)).width for web_img in self.img_list
)
total_height = sum(
Image.open(io.BytesIO(web_img.data)).height for web_img in self.img_list
)
# 创建一张新的长图
long_image = Image.new(
"RGB", (max_width, total_height), color=(255, 255, 255)
)
# 依次将图片在垂直方向上拼接起来
y_offset = 0
for web_img in self.img_list:
img = Image.open(io.BytesIO(web_img.data))
img_width, img_height = img.size
x_offset = (max_width - img_width) // 2 # 居中拼接
long_image.paste(img, (x_offset, y_offset))
y_offset += img_height
return long_image
except Exception as e:
task_name = self.img_list[0].task_name
print(f"{task_name}, 拼接图片失败:{e}")
return None
def save_long_image(self):
long_image = self.concatenate_images_vertically() # 垂直拼接长图片
long_image.save(f"output/{self.img_list[0].task_name}.png") # 保存长图到本地