Сейчас я напишу тебе программу на языке python, на входе которой словарь с данными, а на…
- User
Сейчас я напишу тебе программу на языке python, на входе которой словарь с данными, а на выходе рисуется картинка, содержащая таблицу. Программа: import pytz import datetime import time import requests import textwrap
from babel.dates import format_date, format_datetime, format_time, get_timezone, UTC
from PIL import Image, ImageDraw, ImageFont
def draw_date_header(image, text, font, row_height, start_coordinate_x, start_coordinate_y): overlay = Image.new('RGBA', image.size, (255, 255, 255, 0)) draw_overlay = ImageDraw.Draw(overlay) # Create a context for drawing things on it. original_image = image
codecell_text = text # Находим размер текста с помощью метода font.getbbox text_bbox = font.getbbox(cell_text) text_height = text_bbox[3] - 20 text_x = start_coordinate_x text_y = start_coordinate_y + (row_height - text_height) // 2 # Рисуем тень shadow_color = (0, 0, 0) shadow_x = text_x + 2 shadow_y = text_y + 2 draw_overlay.text((shadow_x, shadow_y), text, fill=shadow_color, font=font) draw_overlay.text((text_x, text_y), cell_text, fill=(255, 255, 255), font=font) # Alpha composite these two images together to obtain the desired result. original_image = Image.alpha_composite(original_image, overlay) image = original_image return imagedef find_table_width(column_widths, column_spacing): cell_width = 0 for i in range(0, len(column_widths)):
cell_width = cell_width + column_widths[i] + column_spacing return cell_widthdef add_weather_icon(image, weather_icon, cell_width, row_height, start_coordinate_x, start_coordinate_y): cell_image = Image.open(weather_icon) cell_image.thumbnail((40, 40)) cell_image_width, cell_image_height = cell_image.size image_x = start_coordinate_x + (cell_width - cell_image_width) // 2 image_y = start_coordinate_y + (row_height - cell_image_height) // 2 image.paste(cell_image, (image_x, image_y), cell_image)
def add_thermometer_icon(image, draw, font, rain_probability, cell_width, row_height, start_coordinate_x, start_coordinate_y): cell_image = Image.open("general_icons/thermometer.png").convert("RGBA") # Изменение размеров иконки термометра cell_image.thumbnail((35, 35)) cell_image_width, cell_image_height = cell_image.size
code - Assistant
Функцию, которая добавляет текст Гран-При Эмилии-Романьи и флаг на оригинальное изображение, можно написать следующим образом:
pythondef add_text_and_flag(image): # Открываем изображение флага flag_image = Image.open("flag.png").convert("RGBA") # Уменьшаем картинку с флагом до нужного размера flag_image.thumbnail((100, 100)) # Выравниваем флаг по ширине оригинального изображения table_width, _ = image.size flag_width, flag_height = flag_image.size x = (table_width - flag_width) // 2 # координата X, чтобы разместить флаг по центру по горизонтали # Стартовая координата по высоте y = 150 # Добавляем флаг на оригинальное изображение image.paste(flag_image, (x, y), flag_image) # Добавляем текст "Гран-При Эмилии-Ром
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.