Script Python "generate" : Différence entre versions

De Les Fabriques du Ponant
Aller à : navigation, rechercher
(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... »)
 
Ligne 1 : Ligne 1 :
ce texte est à enregistrer dans un fichier à nommer generate.py et l'exécuter en python.
+
Le texte du script 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
 
source : pixelstick par Lucas Berbesson for LA FABRIQUE DIY LICENSE MIT
  
 
Voir https://github.com/LucasBerbesson/pixelstick
 
Voir https://github.com/LucasBerbesson/pixelstick
 +
==Jouer le script python==
 +
===Sous Mac===
 +
ouvrir le fichier avec IDDLE (interface graphique de python installée par défaut sur mac), dans le menu cliquer sur "Run" puis sur "Run Module"
 +
 +
===Sous Linux===
 +
?
 +
===Sous Windows===
 +
?
 
==le script==
 
==le script==
 
<pre>
 
<pre>

Version du 21 octobre 2019 à 16:26

Le texte du script 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

Jouer le script python

Sous Mac

ouvrir le fichier avec IDDLE (interface graphique de python installée par défaut sur mac), dans le menu cliquer sur "Run" puis sur "Run Module"

Sous Linux

?

Sous Windows

?

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()