python - 我怎样才能用Python创建框架,我可以将图片放入框架中

标签 python image-processing

我想把我的照片放在相框里。我用了这个鳕鱼:

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/

相关文章:

image-processing - 如何根据颜色和大小分割对象?

image-processing - 图像算法中的图像

python-3.x - 使用 OpenCV 比较两个图像

python - 将相似的模式合并为单一的共识模式

python - 如何降级openssl

python - 有更好的查字方法吗?

image - 如何在 Matlab 中傅立叶相位扰乱灰度 JPEG 图像?

具有不同光照的 OpenCV 背景减法

Python 的 sum() 会将字符串列表加在一起。有什么用?

python - 任何 n_jobs 进行交叉验证的内存泄漏