Форум сайта python.su
Добрый день. Играюсь с данной библиотекой и возникла “загвоздка”, не получается переместить вставляемое изображение, пишет несоответствие размеров.
Traceback (most recent call last): File "C:/Python34/constest/createImage.py", line 34, in <module> imageCreator("id_111_33333.png", 123) File "C:/Python34/constest/createImage.py", line 12, in imageCreator image.paste(qr_image, (1,0,x,y)) File "C:\Python34\lib\site-packages\PIL\Image.py", line 1351, in paste self.im.paste(im, box) ValueError: images do not match
from PIL import Image from PIL import ImageFont from PIL import ImageDraw from PIL import ImageOps def imageCreator(link, ident): size = width, height = 39, 43 image = Image.new("1", size, "#ccc") qr_image = Image.open(link, 'r') x, y = qr_image.size image.paste(qr_image, (0,0,x,y)) id_size = len(str(ident)) if id_size: null = str() while id_size != 7: id_size +=1 null += '0' ident = str(null) + str(ident) # draw image draw = ImageDraw.Draw(image) font = ImageFont.truetype("tahoma.ttf", 9) draw.text((3, 33), ident, "#000", font=font) final_image = ImageOps.expand(image, border=1, fill='black') final_image.save("file.png") final_image.show() imageCreator("id_111_33333.png", 123)
image.paste(qr_image, (1,0,x,y))
Прикреплённый файлы: id_111_33333.png (233 байта)
Офлайн