from PIL import Image, ImageDraw, ImageFont import qrcode def generate_qr_code(url): return qrcode.make(url) def draw_multiple_line_text(input_image_size, text, font=None, text_color=(255, 255, 255)): if font is None: font = ImageFont.load_default() watermark_image = Image.new("RGB", input_image_size, (0, 0, 0)) output_image = watermark_image.copy() draw = ImageDraw.Draw(watermark_image) image_width, image_height = input_image_size line_width, line_height = font.getsize(text) draw.text( ((image_width - line_width)/2, (image_height - line_height)/2), text, font=font, fill=text_color ) scale = min(image_width / line_width, image_height / line_height) watermark_image = watermark_image.resize((int(watermark_image.width * scale), int(watermark_image.height*scale))) output_image.paste(watermark_image, (int((image_width-watermark_image.width)/2), int((image_height-watermark_image.height)/2))) return output_image