斜向旋转

This commit is contained in:
changjiaxiang
2024-07-16 18:52:56 +08:00
parent 700c0a0b6f
commit 868dee5a90
2 changed files with 44 additions and 1 deletions
+26 -1
View File
@@ -12,6 +12,7 @@ from .videoCut import getCutList, video_to_frames, cutToDir, frames_to_video
from .seg import get_masks
from .line_editor import fill_white_segments, find_largest_white_component
from .color_editor import get_colors, find_similar_colors, most_common_fuzzy_color, detect_outline,hex_to_rgba
from .image_editor import rotate_image_with_padding
from .pixel import *
import gc
import sys
@@ -1624,6 +1625,29 @@ class GETRequset:
else:
return (f"请求失败,状态码:{response.status_code}",)
class RotateImageWithPadding:
def __init__(self) -> None:
pass
@classmethod
def INPUT_TYPES(s):
return {
"required": {
"original_image": ("IMAGE",),
},
}
CATEGORY = "badger"
RETURN_TYPES = ("IMAGE",)
FUNCTION = "rotate_and_pad_image"
OUTPUT_NODE = True
def rotate_and_pad_image(self,original_image):
img_PIL = tensorToImg(original_image)
result = rotate_image_with_padding(img_PIL)
img_tensor = imgToTensor(result)
garbage_collect()
return (img_tensor,)
NODE_CLASS_MAPPINGS = {
"ImageOverlap-badger": ImageOverlap,
@@ -1659,7 +1683,8 @@ NODE_CLASS_MAPPINGS = {
"GarbageCollect-badger": GarbageCollect,
"ToPixel-badger": ToPixel,
"SimpleBoolean-badger": SimpleBoolean,
"GETRequset-badger": GETRequset
"GETRequset-badger": GETRequset,
"RotateImageWithPadding":RotateImageWithPadding
}
+18
View File
@@ -0,0 +1,18 @@
import math
from PIL import Image
def rotate_image_with_padding(img:Image):
# 创建一个空画布,
canvas_size = (img.width * 3, img.height)
canvas = Image.new('RGB', canvas_size, color='white')
# 将原图片复制为三张,横着放着一行,居中放置在画布上
for i in range(3):
canvas.paste(img, (img.width * i + (canvas.width - img.width * 3) // 2, (canvas.height - img.height) // 2))
# 将图片旋转45度,空白的地方用白色填上
canvas = canvas.rotate(315, expand=True, fillcolor='white')
point_x = (5*math.sqrt(2)-2)*img.width/4
point_y = (3*math.sqrt(2)-2)*img.width/4
croped_img = canvas.crop((point_x, point_y, point_x+img.width, point_y+img.height))
return croped_img