This commit is contained in:
@ -178,11 +178,13 @@ async def apply_filters_to_images(images: list[Image.Image], filters: list[Filte
|
|||||||
output = BytesIO()
|
output = BytesIO()
|
||||||
if getattr(img, "is_animated", False) or frozen_to_move:
|
if getattr(img, "is_animated", False) or frozen_to_move:
|
||||||
frames = []
|
frames = []
|
||||||
|
append_images = []
|
||||||
if getattr(img, "is_animated", False):
|
if getattr(img, "is_animated", False):
|
||||||
logger.debug("处理动图帧")
|
logger.debug("处理动图帧")
|
||||||
else:
|
else:
|
||||||
# 将静态图视作单帧动图处理,拷贝多份
|
# 将静态图视作单帧动图处理,拷贝 10 帧
|
||||||
logger.debug("处理静态图为多帧动图")
|
logger.debug("处理静态图为多帧动图")
|
||||||
|
append_images = [img.copy() for _ in range(10)]
|
||||||
img.info['duration'] = int(1000 / static_fps)
|
img.info['duration'] = int(1000 / static_fps)
|
||||||
|
|
||||||
async def process_single_frame(frame_images: list[Image.Image], frame_idx: int) -> Image.Image:
|
async def process_single_frame(frame_images: list[Image.Image], frame_idx: int) -> Image.Image:
|
||||||
@ -195,7 +197,7 @@ async def apply_filters_to_images(images: list[Image.Image], filters: list[Filte
|
|||||||
# 并发处理所有帧
|
# 并发处理所有帧
|
||||||
tasks = []
|
tasks = []
|
||||||
all_frames = []
|
all_frames = []
|
||||||
for i, frame in enumerate(ImageSequence.Iterator(img)):
|
for i, frame in enumerate(list(ImageSequence.Iterator(img)) + append_images):
|
||||||
all_frames.append(frame.copy())
|
all_frames.append(frame.copy())
|
||||||
images_copy = copy_images_by_index(images, i)
|
images_copy = copy_images_by_index(images, i)
|
||||||
task = process_single_frame(images_copy, i)
|
task = process_single_frame(images_copy, i)
|
||||||
|
|||||||
@ -1071,8 +1071,6 @@ class ImageFilterImplement:
|
|||||||
if image.mode != 'RGBA':
|
if image.mode != 'RGBA':
|
||||||
image = image.convert('RGBA')
|
image = image.convert('RGBA')
|
||||||
|
|
||||||
width, height = image.size
|
|
||||||
arr = np.array(image)
|
|
||||||
# 生成随机偏移
|
# 生成随机偏移
|
||||||
x_offset = random.randint(-max_offset, max_offset)
|
x_offset = random.randint(-max_offset, max_offset)
|
||||||
y_offset = random.randint(-max_offset, max_offset)
|
y_offset = random.randint(-max_offset, max_offset)
|
||||||
|
|||||||
Reference in New Issue
Block a user