Ci-dessous, les différences entre deux révisions de la page.
Prochaine révision | Révision précédente | ||
python:pillow [2021/08/25 05:34] marclebrun créée |
python:pillow [2021/08/29 05:53] (Version actuelle) |
||
---|---|---|---|
Ligne 1: | Ligne 1: | ||
- | ====== Pillow ====== | + | ====== Pillow (PIL) ====== |
- | Doc : [[https://python-pillow.org/]] | + | * Site officiel : [[https://python-pillow.org/]] |
+ | * Doc : [[https://pillow.readthedocs.io/en/stable/]] | ||
+ | |||
+ | ===== Création d'une image ===== | ||
+ | |||
+ | Source: [[https://pythonexamples.org/python-pillow-create-image/]] | ||
+ | |||
+ | Ce code crée une image en mode **RGB** de dimension **640 x 480** | ||
+ | dont la couleur de fond sera **rgb(255, 255, 255)** (jaune) : | ||
+ | |||
+ | <code python> | ||
+ | from PIL import Image | ||
+ | |||
+ | im = Image.new('RGB', (640, 480), (255, 255, 0)) | ||
+ | im.show() | ||
+ | </code> | ||
+ | |||
+ | La fonction **show** ouvre l'image générée dans le programme de visualisation | ||
+ | par défaut du système. | ||
+ | |||
+ | ===== Dessiner sur l'image créée ===== | ||
+ | |||
+ | Source: [[https://www.geeksforgeeks.org/python-pil-imagedraw-draw-rectangle/]] | ||
+ | |||
+ | <code python> | ||
+ | from PIL import Image, ImageDraw | ||
+ | |||
+ | w, h = 320, 200 | ||
+ | |||
+ | image = Image.new('RGB', (w, h), (255, 255, 255)) | ||
+ | |||
+ | draw = ImageDraw.Draw(image) | ||
+ | draw.rectangle( | ||
+ | [(40, 40), (w-40, h-40)], | ||
+ | fill="#00FF00", | ||
+ | outline="red" | ||
+ | ) | ||
+ | |||
+ | image.show() | ||
+ | |||
+ | </code> | ||