如何用 pil 制作每种颜色的组合?
How to make every combination of colors with pil?
我想从不同的调色板中进行一些组合,因此我需要为调色板 webhexred 中的每种颜色和调色板 webhexyel 中的每种颜色创建。我想更改这张图片的颜色。
我该怎么做?
from PIL import Image
import numpy as np
im = Image.open('AGXCL.jpg')
imnp = np.array(im)
webhexred = {
"lightsalmon" : "#FFA07A",
"salmon" :"#FA8072",
"darksalmon" : "#E9967A",
"lightcoral" : "#F08080"
}
webhexyel = {
"goldenrod" : "#DAA520",
"gold": "#FFD700",
"orange" : "#FFA500",
"darkorange" : "#FF8C00"
}
output.save( webhexred + "_" + webhexyel + ".png")
您不需要 numpy,也不需要输入图像。使用嵌套循环 运行 遍历两个列表。创建一个新图像,填充一种颜色,然后使用 ImageDraw
绘制另一种颜色。
from PIL import Image, ImageDraw
webhexred = {
"lightsalmon" : "#FFA07A",
"salmon" :"#FA8072",
"darksalmon" : "#E9967A",
"lightcoral" : "#F08080"
}
webhexyel = {
"goldenrod" : "#DAA520",
"gold": "#FFD700",
"orange" : "#FFA500",
"darkorange" : "#FF8C00"
}
for topname,top in webhexred.items():
for botname,bot in webhexyel.items():
output = Image.new('RGB', (256,256), top)
dc = ImageDraw.Draw(output)
dc.rectangle( ((0,128),(256,256)), bot, bot)
output.save( topname + "_" + botname + ".png")
我想从不同的调色板中进行一些组合,因此我需要为调色板 webhexred 中的每种颜色和调色板 webhexyel 中的每种颜色创建。我想更改这张图片的颜色。
我该怎么做?
from PIL import Image
import numpy as np
im = Image.open('AGXCL.jpg')
imnp = np.array(im)
webhexred = {
"lightsalmon" : "#FFA07A",
"salmon" :"#FA8072",
"darksalmon" : "#E9967A",
"lightcoral" : "#F08080"
}
webhexyel = {
"goldenrod" : "#DAA520",
"gold": "#FFD700",
"orange" : "#FFA500",
"darkorange" : "#FF8C00"
}
output.save( webhexred + "_" + webhexyel + ".png")
您不需要 numpy,也不需要输入图像。使用嵌套循环 运行 遍历两个列表。创建一个新图像,填充一种颜色,然后使用 ImageDraw
绘制另一种颜色。
from PIL import Image, ImageDraw
webhexred = {
"lightsalmon" : "#FFA07A",
"salmon" :"#FA8072",
"darksalmon" : "#E9967A",
"lightcoral" : "#F08080"
}
webhexyel = {
"goldenrod" : "#DAA520",
"gold": "#FFD700",
"orange" : "#FFA500",
"darkorange" : "#FF8C00"
}
for topname,top in webhexred.items():
for botname,bot in webhexyel.items():
output = Image.new('RGB', (256,256), top)
dc = ImageDraw.Draw(output)
dc.rectangle( ((0,128),(256,256)), bot, bot)
output.save( topname + "_" + botname + ".png")