我需要的是: - 有两个图像:背景(大)和图像(较小) - 在背景上有一个斜线框,我想在其中合并轮廓PIC粘贴两个文件后图像质量较差
代码:
# open the profile pic
im = PIL.Image.open(pic)
# resize it to dim of oblique box
im = im.resize((picX, picY))
# this is the degree of oblique box
degree = 13.67
# open the background
bg = PIL.Image.open(bgsrc)
bgosize = bg.size
bginfo = bg.info
# first, I rotate the background to be paralell with profile pic
bg = bg.rotate(-degree, resample = PIL.Image.BILINEAR, expand = True)
# paste the profile pic to background
bg.paste(im, (px1, py1, px2, py2))
# rotate back to original orientation
bg = bg.rotate(degree, resample = PIL.Image.BILINEAR, expand = False)
# crop the rotated image, because it's greater than original size,
# after first rotate - coords are stored
bg.crop(bgx1, bgy1, bgx2, bgy2)
PIL.ImageFile.MAXBLOCK = bg.size[0] * bg.size[1]
bg.save(dst, quality = 250, optimize = True, **bginfo)
这个变换后的结果图像是nubbly一个litlebit ...
我怎样才能得到一个良好的育人质量的图像?
感谢:
a。
嗨马克,感谢您的回复, 1:我试过BILINEAR也是 - 它没有效果。 2:如果我首先旋转轮廓图片,它将调整到更大的尺寸,黑色背景 - 如何将JPEG转换/变换为不透明的PNG? 3:我会检查掩码参数,如果你有一个例子,我感谢你:) – airween 2012-03-27 18:19:32
嗨马克,谢谢你的例子。 如果我在im.rotate和mask.rotate之后即时保存图像,那么它们也是非常重要的...因此,即使我打开背景并从PIL中保存它,它也会一目了然。 我的另一个评论:当cr对象(而不是im)被遮罩时,它具有黑色背景 - 我如何创建透明背景?非常感谢: – airween 2012-03-28 08:36:19