python:来自某个范围内的组的图像生成器

发布于 2025-01-11 10:02:46 字数 1172 浏览 0 评论 0原文

我是新来的。 我在网上找到了一个代码,我正在尝试修复一些问题。

我希望我的组使用/查看该组指定文件夹 (*.png) 内的所有文件,而不仅仅是我键入的这些文件。

组1 = [ r“D:/IM/1x/5_0.png”, r“D:/IM/1x/5_1.png”, r"D:/IM/1x/5_2.png"

第 2 组正在使用位于

D:/IM/2x/

的文件,该文件夹中的图片可能多 100 倍 (1x),我不想将每个单独的图片分开行

这是代码。非常感谢您的帮助。 如果没有意义,请询问。

from PIL import Image
group1 = [
  r"D:/IM/1x/5_0.png",
  r"D:/IM/1x/5_1.png",
  r"D:/IM/1x/5_2.png",
  r"D:/IM/1x/5_3.png",
  r"D:/IM/1x/5_4.png",

]

group2 = [
  r"D:/IM/2x/4_0.png",
  r"D:/IM/2x/4_1.png",
  r"D:/IM/2x/4_2.png"

]

group3 = [
  r"D:/IM/3x/3_1.png"

]
counter = 1

def createImage(a,b,c, counter):
  first = group1[a]
  second = group2[b]
  third = group3[c]

  image01 = Image.open(first).convert("RGBA")
  image02 = Image.open(second).convert("RGBA")
  image03 = Image.open(third).convert("RGBA")


  intermediate = Image.alpha_composite(image01, image02)
  intermediate2 = Image.alpha_composite(intermediate, image03)


  name = "D:/DONE/" + str(counter) + ".png"
  intermediate2.save(name)

for a in range(10):
  for b in range(3):
    for c in range(1):
               createImage(a,b,c, counter)
               counter = counter + 1

I am new here.
I found a code online and I am trying to fix some things.

I want my groups to use/see all files inside designated folder (*.png) for that group , not only these I typed.

group1 = [
r"D:/IM/1x/5_0.png",
r"D:/IM/1x/5_1.png",
r"D:/IM/1x/5_2.png"

Group 2 is using files located

D:/IM/2x/

it can be 100x more pictures inside this folder(1x), I do not want to locate every single one as separate line

Here is the code. Thank you very much for any help.
If it does not make sense, please ask.

from PIL import Image
group1 = [
  r"D:/IM/1x/5_0.png",
  r"D:/IM/1x/5_1.png",
  r"D:/IM/1x/5_2.png",
  r"D:/IM/1x/5_3.png",
  r"D:/IM/1x/5_4.png",

]

group2 = [
  r"D:/IM/2x/4_0.png",
  r"D:/IM/2x/4_1.png",
  r"D:/IM/2x/4_2.png"

]

group3 = [
  r"D:/IM/3x/3_1.png"

]
counter = 1

def createImage(a,b,c, counter):
  first = group1[a]
  second = group2[b]
  third = group3[c]

  image01 = Image.open(first).convert("RGBA")
  image02 = Image.open(second).convert("RGBA")
  image03 = Image.open(third).convert("RGBA")


  intermediate = Image.alpha_composite(image01, image02)
  intermediate2 = Image.alpha_composite(intermediate, image03)


  name = "D:/DONE/" + str(counter) + ".png"
  intermediate2.save(name)

for a in range(10):
  for b in range(3):
    for c in range(1):
               createImage(a,b,c, counter)
               counter = counter + 1

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文