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