Skip to content
Snippets Groups Projects
csv_en_png.py 883 B
#!/usr/bin/python3
# -*- coding: utf-8 -*-

"""
:mod:`fonctions` module : convertisseur de fichiers csv pour obtenir en rgb

:author: Louis Chmielewski

:date: 2024 mars

"""

import csv
from PIL import Image, ImageDraw

# Créer une nouvelle image avec un fond noir
width, height = 512, 512
image = Image.new("RGB", (width, height), "black")
draw = ImageDraw.Draw(image)

# Chemin vers le fichier CSV
csv_file = "assets/mystere.csv"

# Lire les données à partir du fichier CSV
with open(csv_file, newline='') as csvfile:
    csv_reader = csv.reader(csvfile)
    for row in csv_reader:
        if len(row) == 7:
            # Convertir les valeurs de la ligne en entiers
            x1, y1, x2, y2, r, g, b = map(int, row)
            # Dessiner un rectangle avec la couleur spécifiée
            draw.rectangle([x1, y1, x2, y2], fill=(r, g, b))

# Afficher l'image
image.show()