اريد سكريبت بايثون احترافي متقن تعطيه كتابة يدمجها في صورة
- User
اريد سكريبت بايثون احترافي متقن تعطيه كتابة يدمجها في صورة
- Assistant
إليك سكريبت بايثن يستخدم مكتبة PIL (Pillow) للقيام بمهمة دمج النصوص في الصور بشكل احترافي. إذا لم تكن قد قمت بتثبيت مكتبة Pillow بعد، يمكنك تثبيتها باستخدام
pip install Pillow.from PIL import Image, ImageDraw, ImageFont def add_text_to_image(image_path, text, position, font_path="arial.ttf", font_size=30, font_color=(255, 255, 255)): """ Adds text to an image. :param image_path: path to the image file :param text: the text to add to the image :param position: a tuple (x, y) of where to add the text :param font_path: path to the font file (.ttf), default is 'arial.ttf' :param font_size: size of the font, default is 30 :param font_color: a tuple (R, G, B) for the color of the font, default is white (255, 255, 255) """ # Open the image image = Image.open(image_path) # Initialize ImageDraw draw = ImageDraw.Draw(image) # Specify the font file and the size font = ImageFont.truetype(font_path, font_size) # Add text to image draw.text(position, text, font_color, font=font) # Save the edited image image.save('output_image.png') print("Text has been added to the image and saved as 'output_image.png'") # Example usage add_text_to_image('path/to/your/image.jpg', 'Your text here', position=(10, 10), font_path='path/to/your/font.ttf', font_size=50, font_color=(0, 0, 0))
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.