Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

from PIL import Image, ImageDraw, ImageFont import random Open the target image…

  1. User

    from PIL import Image, ImageDraw, ImageFont import random

    Open the target image

    image_path = "C:\Users\click\Downloads\panda.jpg" image = Image.open(image_path)

    Get the user's name

    user_name = input("Enter your name: ")

    Define the position of the signature

    signature_position = (image.width - 400, image.height - 100)

    Define the signature style

    font_path = "C:\Users\click\Downloads\Southam Demo.otf" font_size = 30 text_color = (0, 0, 0) # Black color

    Create a new image for the signature

    signature_image = Image.new("RGBA", (400, 100), (0, 0, 0, 0)) draw = ImageDraw.Draw(signature_image)

    Load the selected font and write the signature text

    font = ImageFont.truetype(font_path, font_size) draw.text((10, 10), user_name, font=font, fill=text_color)

    Apply some random effects to simulate a hand-drawn signature

    for _ in range(500): x = random.randint(0, 400) y = random.randint(0, 100) color = ( random.randint(0, 255), random.randint(0, 255), random.randint(0, 255), random.randint(100, 200), ) draw.point((x, y), fill=color)

    Create a transparent overlay for the signature

    overlay = Image.new("RGBA", image.size, (0, 0, 0, 0)) overlay.paste(signature_image, signature_position)

    Composite the overlay onto the image

    image_with_signature = Image.alpha_composite(image.convert("RGBA"), overlay)

    Save the image with the signature

    image_with_signature.save("C:\Users\click\Downloads\panda_signed.png") ليه الكود مش بيرن

  2. Assistant

    يبدو أنك قمت بنسيان وضع علامة تعليق لنهاية السطر الذي يحتوي على الأمر image_with_signature.save("C:\\Users\\click\\Downloads\\panda_signed.png"). إذا قمت بإضافة علامة تعليق "#" لنهايتها بعد رمز "png"، يجب أن يتم تشغيل الأمر بشكل صحيح. السطر النموذجي يجب أن يبدو كالتالي:

    image_with_signature.save("C:\\Users\\click\\Downloads\\panda_signed.png")  # ليه الكود مش بيرن
    

    تأكد من حفظ التغييرات وتشغيل البرنامج مرة أخرى.