Script Python "generate"
Révision datée du 21 octobre 2019 à 15:23 par Antonydbzh (discussion | contributions) (Page créée avec « ce texte est à enregistrer dans un fichier à nommer generate.py et l'exécuter en python. source : pixelstick par Lucas Berbesson for LA FABRIQUE DIY LICENSE MIT Voir... »)
ce texte est à enregistrer dans un fichier à nommer generate.py et l'exécuter en python.
source : pixelstick par Lucas Berbesson for LA FABRIQUE DIY LICENSE MIT
Voir https://github.com/LucasBerbesson/pixelstick
le script
"""
Written by Lucas Berbesson for LA FABRIQUE DIY
LICENSE MIT
"""
import os
from os.path import basename
from PIL import Image
for filename in os.listdir('.'):
if filename.endswith(".png") or filename.endswith(".jpg"):
text_file_name = "{}.txt".format(os.path.splitext(filename)[0])
text_file = open(text_file_name, "w+")
im = Image.open(filename)
im = im.rotate(90,expand=True)
im.save("test.png")
pixels = list(im.getdata())
for pixel in pixels:
try:
red,green,blue,brightness = pixel
text_file.write("{}, {}, {}\n".format(red,green,blue))
except:
print(text_file_name)
text_file.write("300, 300, 300")
text_file.close()
