79605994

Date: 2025-05-04 19:58:49
Score: 3.5
Natty:
Report link
# Crear una lista única de colores y sus códigos hexadecimales con sus valores RGB decimales
unique_colors = {}
for y in range(grid_size):
    for x in range(grid_size):
        rgb = tuple(pixels[y][x])
        hex_code = '#%02x%02x%02x' % rgb
        if hex_code not in unique_colors:
            unique_colors[hex_code] = rgb

# Crear imagen principal con grid 32x32 como antes
main_grid_image = Image.new("RGB", output_size, "white")
draw_main = ImageDraw.Draw(main_grid_image)

for y in range(grid_size):
    for x in range(grid_size):
        color = tuple(pixels[y][x])
        top_left = (x * cell_size, y * cell_size)
        bottom_right = ((x + 1) * cell_size, (y + 1) * cell_size)
        draw_main.rectangle([top_left, bottom_right], fill=color, outline="black")

# Crear una leyenda abajo con los códigos hexadecimales y sus valores decimales
legend_cell_height = 30
legend_height = len(unique_colors) * legend_cell_height
legend_width = output_size[0]
legend_image = Image.new("RGB", (legend_width, legend_height), "white")
draw_legend = ImageDraw.Draw(legend_image)

# Usar fuente pequeña
try:
    legend_font = ImageFont.truetype("DejaVuSans-Bold.ttf", 14)
except IOError:
    legend_font = ImageFont.load_default()

# Dibujar cada entrada de leyenda
for idx, (hex_code, rgb) in enumerate(sorted(unique_colors.items())):
    y_position = idx * legend_cell_height
    draw_legend.rectangle([0, y_position, 30, y_position + legend_cell_height], fill=rgb, outline="black")
    text = f"{hex_code}  ->  RGB {rgb}"
    draw_legend.text((35, y_position + 5), text, fill="black", font=legend_font)

# Combinar la imagen principal y la leyenda
combined_height = output_size[1] + legend_height
combined_image = Image.new("RGB", (output_size[0], combined_height), "white")
combined_image.paste(main_grid_image, (0, 0))
combined_image.paste(legend_image, (0, output_size[1]))

# Guardar imagen final
final_output_file = "/mnt/data/jesus_pixel_grid_with_rgb_legend.png"
combined_image.save(final_output_file)

final_output_file
Reasons:
  • Blacklisted phrase (2): código
  • Blacklisted phrase (2): Crear
  • Long answer (-1):
  • Has code block (-0.5):
  • Low reputation (1):
Posted by: Samuel Ballestas