简体   繁体   English

PIL-从JPG和PNG帧制作1个PNG

[英]PIL - make 1 PNG from JPG and PNG frame

I have 2 images: 我有2张图片:

  • PNG (99x97) with white, rotated frame and rest is in full transparency. 带有白色旋转框架和其余部分的PNG(99x97)完全透明。
  • JPG - is my generated thumbnail (80x80) JPG-是我生成的缩略图(80x80)

Now I want to put thumbnail into my frame so it looks like some kind of painting. 现在,我想将缩略图放入帧中,使其看起来像某种绘画。 What should I do? 我该怎么办?

EDIT: 编辑:

I forgot to add, that picture must be under the frame. 我忘了补充,那张照片必须在框架下。

Frame image 画面图片

I have some script but it shows only a frame. 我有一些脚本,但只显示一个框架。 There is no picture in it :/ 没有图片:/

import Image, ImageDraw

img_size = (99,97)
im = Image.open('logo.jpg')
picture = im.crop((0,0,80,80))
frame = Image.open('thumb-frame.png')
picture = picture.convert('RGBA')
background = Image.new('RGBA', img_size, (255, 255, 255, 0))
background.paste(picture, (10,9))
background.paste(frame, (0,0))
background.save('logocopy.png', 'PNG')

EDIT: 编辑:

Problem solved. 问题解决了。 I had to add alpha mask to .paste() 我必须在.paste()中添加Alpha蒙版

import Image

im = Image.open('logo.jpg')
picture = im.crop((0,0,80,80))
picture = picture.convert('RGBA')
frame = Image.open('thumb-frame.png')
background = Image.new('RGBA', frame.size, (255, 255, 255, 0))
background.paste(picture, (10,9))
background.paste(frame, (0,0), frame)
background.save('logocopy.png', 'PNG')

Here you go. 干得好。 This should take original picture and paste transparent frame image above it. 这应该拍摄原始图片,并在其上方粘贴透明框架图像。 Both pictures should be 100x100, but you can add needed resizing. 两张图片均应为100x100,但是您可以添加所需的调整大小。

from PIL import Image

frame = Image.open('frame.png')
img = Image.open('image.jpg')

img_dest = img.copy().convert('RGBA')
img_dest.paste(frame, (0, 0, 100, 100), frame)

img_dest = img_dest.convert('RGB') # Optional, to remove transparency info

img_dest.save('output.png')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM