我正在为照片创建一个方形的白色画布/图像。然后我将我的图像粘贴到新画布的中心,一切都很好。但是,图像的颜色会发生变化。我无法弄清楚要修改哪个变量来解决这个问题。
这是我的代码:
img = Image.open(llt)
img_w, img_h = img.size
newImage = Image.new("RGB", (max(img_w, img_h),max(img_w, img_h)),"white")
bg_w, bg_h = newImage.size
offset = (round((bg_w - img_w) / 2), round((bg_h - img_h) / 2))
newImage.paste(img, offset)
newImage.show()
答案 0 :(得分:0)
尝试像这样保存图片:
llt = "the_image.ext"
img = Image.open(llt)
img_w, img_h = img.size
newImage = Image.new("RGB", (max(img_w, img_h),max(img_w, img_h)),"white")
bg_w, bg_h = newImage.size
offset = (int(round((bg_w - img_w) / 2)), int(round((bg_h - img_h) / 2)))
newImage.paste(img, offset)
newImage.save("modified.jpg");
#newImage.show()
llt = "the_image.ext"
img = Image.open(llt)
img_w, img_h = img.size
newImage = Image.new("RGB", (max(img_w, img_h),max(img_w, img_h)),"white")
bg_w, bg_h = newImage.size
offset = (int(round((bg_w - img_w) / 2)), int(round((bg_h - img_h) / 2)))
newImage.paste(img, offset)
newImage.save("modified.jpg");
#newImage.show()