参考链接: Tutorial
参考链接: PIL.Image.new(mode, size, color=0)
参考链接: Image.paste(im, box=None, mask=None)
代码展示:
from PIL import Image
im = Image.new('RGB', (400,600), color=(202,209,10))
print(im.format, im.size, im.mode) # None (400, 600) RGB
im.show()
运行效果:
方法: Image.paste(im, box=None, mask=None)
代码:
from PIL import Image
im = Image.new('RGB', (1200,900), color=(0,0,250))
print(im.format, im.size, im.mode) # None (400, 600) RGB
im2 = im
# im.show()
print(id(im))
out = Image.open("bryant.jpg")
out = out.resize((100 * 5, 67 * 5))
im.paste(out, box=(500,100))
print(id(im))
print(id(im2)==id(im))
im.show()
运行结果:
注意:box的取值可以是负数,表示在图片左上角之外:
from PIL import Image
im = Image.new('RGB', (1200,900), color=(0,0,250))
print(im.format, im.size, im.mode) # None (400, 600) RGB
im2 = im
# im.show()
print(id(im))
out = Image.open("bryant.jpg")
out = out.resize((100 * 5, 67 * 5))
# im.paste(out, box=(500,100))
im.paste(out, box=(-200,-100))
print(id(im))
print(id(im2)==id(im))
im.show()
效果显示: