Commit 04199b24 authored by Romain Casati's avatar Romain Casati
Browse files

Adding PIL example.

parent 6f881cee
Pipeline #381231 passed with stages
in 3 minutes and 48 seconds
{"cells":[{"metadata":{"trusted":true},"cell_type":"code","source":"import math\nfrom PIL import Image, ImageDraw\n\n#\nw, h = 120, 90\nbbox = [(10, 10), (w - 10, h - 10)]\n\n# ----------------------------------------------------------\n# rectangle\nimg = Image.new(\"RGB\", (w, h), \"#f9f9f9\") # create new Image\ndctx = ImageDraw.Draw(img) # create drawing context\ndctx.rectangle(bbox, fill=\"#ddddff\", outline=\"blue\")\ndel dctx # destroy drawing context\nimg.show()\n\n# ----------------------------------------------------------\n# ellipse\nimg = Image.new(\"RGB\", (w, h), \"#f9f9f9\") # create new Image\ndctx = ImageDraw.Draw(img) # create drawing context\ndctx.ellipse(bbox, fill=\"#ddddff\", outline=\"blue\")\ndel dctx # destroy drawing context\nimg.show()\n\n# ----------------------------------------------------------\n# arc (end=130)\nimg = Image.new(\"RGB\", (w, h), \"#f9f9f9\") # create new Image\ndctx = ImageDraw.Draw(img) # create drawing context\ndctx.arc(bbox, start=20, end=130, fill=\"blue\")\ndel dctx # destroy drawing context\nimg.show()\n\n# chord (end=130)\nimg = Image.new(\"RGB\", (w, h), \"#f9f9f9\") # create new Image\ndctx = ImageDraw.Draw(img) # create drawing context\ndctx.chord(bbox, start=20, end=130, fill=\"#ddddff\", outline=\"blue\")\ndel dctx # destroy drawing context\nimg.show()\n\n# pieslice (end=130)\nimg = Image.new(\"RGB\", (w, h), \"#f9f9f9\") # create new Image\ndctx = ImageDraw.Draw(img) # create drawing context\ndctx.pieslice(bbox, start=20, end=130, fill=\"#ddddff\", outline=\"blue\")\ndel dctx # destroy drawing context\nimg.show()\n\n# ----------------------------------------------------------\n# arc (end=300)\nimg = Image.new(\"RGB\", (w, h), \"#f9f9f9\") # create new Image\ndctx = ImageDraw.Draw(img) # create drawing context\ndctx.arc(bbox, start=20, end=300, fill=\"blue\")\ndel dctx # destroy drawing context\nimg.show()\n\n# chord (end=300)\nimg = Image.new(\"RGB\", (w, h), \"#f9f9f9\") # create new Image\ndctx = ImageDraw.Draw(img) # create drawing context\ndctx.chord(bbox, start=20, end=300, fill=\"#ddddff\", outline=\"blue\")\ndel dctx # destroy drawing context\nimg.show()\n\n# pieslice (end=300)\nimg = Image.new(\"RGB\", (w, h), \"#f9f9f9\") # create new Image\ndctx = ImageDraw.Draw(img) # create drawing context\ndctx.pieslice(bbox, start=20, end=300, fill=\"#ddddff\", outline=\"blue\")\ndel dctx # destroy drawing context\nimg.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"img","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"from PIL import Image\n\n# auteur de cette image : Romain Casati\n# elle est placée dans le domaine public\nimg = Image.open(\"moon.jpg\")\n\nimg","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"import matplotlib.pyplot as plt\n\nplt.figure(figsize=(9, 5))\nplt.bar(range(256), img.histogram())\nplt.yscale('log')\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"name":"python3","display_name":"Python 3","language":"python"},"celltoolbar":"Slideshow","rise":{"scroll":true,"enable_chalkboard":true}},"nbformat":4,"nbformat_minor":2}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment