CoolFace
Apppublic

ALSv/wmark

sourceHugging Faceapache-2.0updated 3y agoView on Hugging Face
0likes
utils.py25 linesDownload Raw Back to util_functions
1from PIL import Image, ImageDraw, ImageFont2import qrcode3 4def generate_qr_code(url):5    return qrcode.make(url)6 7def draw_multiple_line_text(input_image_size, text, font=None, text_color=(255, 255, 255)):8    if font is None: 9        font = ImageFont.load_default()10    watermark_image = Image.new("RGB", input_image_size, (0, 0, 0))11    output_image = watermark_image.copy()12    draw = ImageDraw.Draw(watermark_image)13    image_width, image_height = input_image_size14    line_width, line_height = font.getsize(text)15    draw.text(16        ((image_width - line_width)/2, (image_height - line_height)/2),17        text,18        font=font,19        fill=text_color20    )21 22    scale = min(image_width / line_width, image_height / line_height)23    watermark_image = watermark_image.resize((int(watermark_image.width * scale), int(watermark_image.height*scale)))24    output_image.paste(watermark_image, (int((image_width-watermark_image.width)/2), int((image_height-watermark_image.height)/2)))25    return output_image