1
我正在为每张票创建QR码。 QRcode是图像格式。 使用python pil扩展图像并在扩展区域添加文本
我想在两侧(即顶部和底部)垂直延伸此图像。而在扩展区域我想添加一些像这样的额外数据:
Theater Name
_____________________
| |
| |
| QR CODE |
| |
| |
| |
| |
| |
|___________________|
Seat id: 24 C
Movie: The baby boss
Showtime: 2:30 pm
Date: 09/04/17
现在我这样做的方法来添加图像:
image = Image.open('qrcode.jpg')
width, height = image.size
draw = ImageDraw.Draw(image)
text_cinema = "RPG Cinema"
text_seat = "Seat: 15C Balcony"
text_movie = "The baby boss"
text_showtime = "02:30 pm"
text_date = "09/04/17"
font = ImageFont.truetype('font.ttf', 24)
draw.text((40, 5), text_cinema, font=font)
draw.text((40,height - 40), text_seat, font=font)
draw.text((40,height + 40), text_movie, font=font)
draw.text((40,height + 40), text_showtime, font=font)
image.save(str(time()).replace('.', '_') + '.jpg')
和图像变成了这样:
正如您所看到的,文本被添加到图像中,而不是扩展图像本身。此外,其他数据(如text_movie
,text_showtime
和text_date
)未被插入,因为文本不会扩展图像。
如何扩展图像并将文本插入扩展图像区域?
下面是扩大图像的建议:https://stackoverflow.com/questions/1572691/in-python-python-image-library-1-1-6-how-can-i- expand-the-canvas-without-resiz(我之前的评论与错误的问题有关)。 – Craig