From bc86bf84d68202f9b3aa401aa4c2ddbc264d403d Mon Sep 17 00:00:00 2001 From: fujammy <467918@qq.com> Date: Thu, 26 Dec 2024 01:10:23 +0800 Subject: [PATCH] =?UTF-8?q?Enhanced=20image=20resizing=20with=20customizab?= =?UTF-8?q?le=20background=20colors.=20Updated=20resize=5Fimage=20to=20use?= =?UTF-8?q?=20a=20specified=20background=20color=20and=20improved=20the=20?= =?UTF-8?q?background=5Fcolor=20parameter=20for=20better=20consistency.=20?= =?UTF-8?q?fix=20bug=20=E4=BC=98=E5=8C=96=E5=9B=BE=E5=83=8F=E7=BC=A9?= =?UTF-8?q?=E6=94=BE=E5=8A=9F=E8=83=BD=EF=BC=8C=E6=94=AF=E6=8C=81=E8=87=AA?= =?UTF-8?q?=E5=AE=9A=E4=B9=89=E8=83=8C=E6=99=AF=E9=A2=9C=E8=89=B2=E3=80=82?= =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BA=86=20resize=5Fimage=20=E5=87=BD?= =?UTF-8?q?=E6=95=B0=E4=BB=A5=E4=BD=BF=E7=94=A8=E6=8C=87=E5=AE=9A=E7=9A=84?= =?UTF-8?q?=E8=83=8C=E6=99=AF=E9=A2=9C=E8=89=B2=EF=BC=8C=E5=B9=B6=E6=94=B9?= =?UTF-8?q?=E8=BF=9B=E4=BA=86=E9=85=8D=E7=BD=AE=E4=B8=AD=E7=9A=84=20backgr?= =?UTF-8?q?ound=5Fcolor=20=E5=8F=82=E6=95=B0=EF=BC=8C=E7=A1=AE=E4=BF=9D?= =?UTF-8?q?=E5=A4=84=E7=90=86=E7=9A=84=E4=B8=80=E8=87=B4=E6=80=A7=E3=80=82?= =?UTF-8?q?=E8=BF=99=E4=B8=80=E6=9B=B4=E6=96=B0=E6=8F=90=E5=8D=87=E4=BA=86?= =?UTF-8?q?=E7=94=A8=E6=88=B7=E4=BD=93=E9=AA=8C=EF=BC=8C=E6=8F=90=E4=BE=9B?= =?UTF-8?q?=E4=BA=86=E6=9B=B4=E5=A4=9A=E7=81=B5=E6=B4=BB=E7=9A=84=E5=9B=BE?= =?UTF-8?q?=E5=83=8F=E5=B1=95=E7=A4=BA=E9=80=89=E9=A1=B9=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __pycache__/__init__.cpython-311.pyc | Bin 1884 -> 1853 bytes __pycache__/click_popup.cpython-311.pyc | Bin 1067 -> 1036 bytes __pycache__/color_picker.cpython-311.pyc | Bin 2130 -> 2099 bytes .../dynamic_image_input.cpython-311.pyc | Bin 2132 -> 2101 bytes .../image_resolution_adjuster.cpython-311.pyc | Bin 13506 -> 13475 bytes __pycache__/install.cpython-311.pyc | Bin 3175 -> 3144 bytes .../multiline_text_input.cpython-311.pyc | Bin 1072 -> 1041 bytes .../remove_empty_lines.cpython-311.pyc | Bin 3656 -> 3625 bytes __pycache__/text_combiner.cpython-311.pyc | Bin 4450 -> 4419 bytes image_resolution_adjuster.py | 11 +++++++++-- 10 files changed, 9 insertions(+), 2 deletions(-) diff --git a/__pycache__/__init__.cpython-311.pyc b/__pycache__/__init__.cpython-311.pyc index a627e8d11212d96dcfbaaadd1165bc28d42f8e34..f2d68ec400252817ae3b2b4f1109826d35ac2402 100644 GIT binary patch delta 52 zcmcb^x0jD^IWI340}v>x=A_HAZ{+*NA|B*v731jX?i}NspPN=0>gkeNmYS1au-S@L Gi3tE~D-ON@ delta 83 zcmdnXcZZK}IWI340}xyk%1M9Dwvq1}i&>$YRg9yjyK_i>eok?WbAE1GWvHi1YFTPd fenBdXA77rCmy%yz9AA)MRFasKle$@&Rf!1zhQ}Px diff --git a/__pycache__/click_popup.cpython-311.pyc b/__pycache__/click_popup.cpython-311.pyc index 4818ffeb2d729c63dc127eb085425e17a0f1dbff..1de41fe707ca10fa65592af78a30b5e7e8678fce 100644 GIT binary patch delta 49 zcmZ3@(Zj*LoR^o20SFXTb2f4dGKz=jWzXhI+cBmZj$87iFykopPy44IWI340}#}SY~(u1C?4i%731jX?i}NspPN=0>gkeNmYS1au$h&~mkj_t C&ke!= delta 79 zcmdlia7ln`IWI340}upl+{ks5(X7%-8m#bKc_gxIX^e8GSt&0wJbF!zaSOH bk1x;6OUW-UjxWeBDoISrN!|R6(U%PX{GA)# diff --git a/__pycache__/dynamic_image_input.cpython-311.pyc b/__pycache__/dynamic_image_input.cpython-311.pyc index ca1b7b309ae3889a3aaaa241634f10ecf7c41293..c3409034bfd951c84260e1c2fb2a57b0882d722d 100644 GIT binary patch delta 48 zcmca2uvLI-IWI340}v>xZsd|>6p!_^igEOGcaCw+&rPcg^>j%sOU=nI*c{9FoecmZ CGY#4R delta 79 zcmdlga7BP?IWI340}w11*~lf!XjbE9731jX?i`YzpHm#;oS&Ok8S3ehT9%rVUyusp b$Cqd3rR0|v#~0)ml_VzRq;9rj{LTgd!-E?8 diff --git a/__pycache__/image_resolution_adjuster.cpython-311.pyc b/__pycache__/image_resolution_adjuster.cpython-311.pyc index 58bafcdebd602efd64dfd87f88b3182610efe741..e9e2c3cc83e020675a5a01d85febe61d170ee6a8 100644 GIT binary patch delta 49 zcmX?x=4|BVPcx delta 80 zcmZ3Sc_@>6IWI340}v#C&)&$*%Wc-=W)FykopPy44h@mzv?IWI340}upl%-+at$7ojIW)FykopPy44x=4|AaU=)w@w2E=`ba#$%&d*J&4E1zLElbVGFW4N(c%2CV DBU%l_ delta 80 zcmbQpv4MkoIWI340}xan$lk~;!Dv?NW)FykopPy44pF diff --git a/__pycache__/remove_empty_lines.cpython-311.pyc b/__pycache__/remove_empty_lines.cpython-311.pyc index 98a5e829274d72b5c8b7d33ea4f472097ee429d6..ed0fb8d5c787d1f6786679e3e2fe5d7336994cbb 100644 GIT binary patch delta 48 zcmX>hvr>j@IWI340}up0*~oRBNj%2WD#p>%-8sfNKR2y1)YB!kEHx*;V6!;0AvXY4 C_zr#m delta 79 zcmZ1}b3%q|IWI340}xzH-pF;G$*kJVD#p>%-8m#bKc_gxIX^e8GSt&0wJbF!zaSOH bk1x;6OUW-UjxWeBDoISrN!|Q|$&ecW5YHSa diff --git a/__pycache__/text_combiner.cpython-311.pyc b/__pycache__/text_combiner.cpython-311.pyc index 8cb2e31e179858a8f7917cea797899a05301744f..0435ebeb29538f677e72355feb90156ed906f0f9 100644 GIT binary patch delta 48 zcmaE)bXbXNIWI340}v>xZsc0SC?4)<731jX?i}NspPN=0>gkeNmYS1au=x#R89x9( CyAHYl delta 79 zcmX@C^hk+oIWI340}wpm-^jIw(X7nPD#p>%-8m#bKc_gxIX^e8GSt&0wJbF!zaSOH bk1x;6OUW-UjxWeBDoISrN!@&wv5X%82HqSG diff --git a/image_resolution_adjuster.py b/image_resolution_adjuster.py index 68039a9..ffa5967 100644 --- a/image_resolution_adjuster.py +++ b/image_resolution_adjuster.py @@ -76,7 +76,14 @@ def resize_image(image, target_width, target_height, method='contain', backgroun new_height = target_height new_width = int(target_height * img_ratio) resized_img = img.resize((new_width, new_height), Image.Resampling.LANCZOS) - padded_img = Image.new('RGB', (target_width, target_height), 'black') + + # 解析背景颜色 + try: + color = tuple(int(background_color.lstrip('#')[i:i+2], 16) for i in (0, 2, 4)) + except ValueError: + color = (0, 0, 0) # 默认黑色 + + padded_img = Image.new('RGB', (target_width, target_height), color) x_offset = (target_width - new_width) // 2 y_offset = (target_height - new_height) // 2 padded_img.paste(resized_img, (x_offset, y_offset)) @@ -246,12 +253,12 @@ class ImageResolutionAdjuster: "images": ("IMAGE",), "target_resolution": (s.get_resolution_options(),), "extend_mode": (["contain", "cover", "fill", "inside", "outside", "top", "bottom", "left", "right", "center"],), - "background_color": ("STRING", {"default": "#000000", "multiline": False}), "scale_factor": ("FLOAT", {"default": 1.0, "min": 0.1, "max": 10.0, "step": 0.1}), "max_width": ("INT", {"default": 2048, "min": 1, "max": 8192, "step": 1}), "max_height": ("INT", {"default": 2048, "min": 1, "max": 8192, "step": 1}), "min_width": ("INT", {"default": 640, "min": 1, "max": 8192, "step": 1}), "min_height": ("INT", {"default": 640, "min": 1, "max": 8192, "step": 1}), + "background_color": ("STRING", {"default": "#000000", "multiline": False}), }, "hidden": {"color_widget": "COMBO"} }