我有一个透明的png图像"foo.png",我打开了另一个图像
im = Image.open("foo2.png");
Run Code Online (Sandbox Code Playgroud)
现在我需要的是将foo.png与foo2.png合并.
(foo.png包含一些文本,我想在foo2.png上打印该文本)
在Python 3.x中运行粘贴脚本时,我不断收到此错误:TypeError:期望的整数参数,得到浮点数
from PIL import Image
img=Image.open('C:\Mine.jpg','r')
img_w,img_h=img.size
background = Image.new('RGBA', (1440,900), (255, 255, 255, 255))
bg_w,bg_h=background.size
offset=((bg_w-img_w)/2,(bg_h-img_h)/2)
background.paste(img,offset)
background.save('C:\new.jpg')
Run Code Online (Sandbox Code Playgroud)
错误MSG:
Traceback (most recent call last):
File "C:\Users\*****\workspace\Canvas Imager\src\Imager.py", line 7, in <module>
background.paste(img,offset)
File "C:\Python33\lib\site-packages\PIL\Image.py", line 1127, in paste
self.im.paste(im, box)
TypeError: integer argument expected, got float
Run Code Online (Sandbox Code Playgroud)
我看到假设是一个整数但最终得到一个浮点数.我该怎么做才能使它成为int?
我在python中使用pyqrcode模块并使用它生成QR代码.如何将徽标放在QR码的中心.
代码看起来像这样
import pyqrcode
data = "Hello World!!"
number = pyqrcode.create(data)
number.png('xyz.png', scale=int(scale))
with open('xyz.png', "rb") as f:
return HttpResponse(f.read(), content_type="image/png")
Run Code Online (Sandbox Code Playgroud)
或者有没有其他方法来做这个而不是pyqrcode?
我正在学习 OpenCV 并尝试将小图像粘贴到大图像上。但是,它显示了一个错误,因为两个图像应该具有相同的大小。我还尝试遵循提供的建议(如何使用 Pillow 将图像粘贴到更大的图像上?)和(如何使用 Python 中的 PIL 将图像合成到另一个图像上?)
import cv2 as cv
from scipy import ndimage
img1 = cv.imread('Please put your file name')
top_left_x = min([x1,x2,x3,x4])
top_left_y = min([y1,y2,y3,y4])
bot_right_x = max([x1,x2,x3,x4])
bot_right_y = max([y1,y2,y3,y4])
y_right =bot_right_y + 1
x_right =bot_right_x + 1
cropped = img[top_left_y: y_right, top_left_x: x_right]
rotate = ndimage.rotate(cropped, ang)
Run Code Online (Sandbox Code Playgroud)
最终输出图像应位于中心。