我想把我的照片放在相框里。我用了这个鳕鱼:
from PIL import Image
img = Image.open('Pic.jpg')
frame = Image.open('Frame.jpg')
size1 = 354,362
paste_point = 69,339
Pic = img.resize((size1))
frame.paste(img, (paste_point))
frame.show()
当我运行该程序时,我的照片没有放入我的框架中。 如何在 python 中创建框架
最佳答案
您的问题解决方案始终取决于您的图片大小和帧大小,因此必须根据图片的像素大小调整代码
我为您的问题提供通用代码可能不适合您的图像标准
from PIL import Image
img = Image.open('Pic.jpg')
img_w, img_h = img.size
frame = Image.new('RGBA', (1440, 900), (255, 255, 255, 255))
bg_w, bg_h = frame.size
offset = ((bg_w - img_w) / 2, (bg_h - img_h) / 2)
frame.paste(img, offset)
frame.save('out.png')
关于python - 我怎样才能用Python创建框架,我可以将图片放入框架中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47235819/