Skip to content

Instantly share code, notes, and snippets.

Created September 27, 2016 12:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/bb174089699ae66443f5a212c5e37b66 to your computer and use it in GitHub Desktop.
Save anonymous/bb174089699ae66443f5a212c5e37b66 to your computer and use it in GitHub Desktop.
pillow testbed
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "from PIL import Image, ImageDraw, ImageFont\n\n# Emulate ev3 screen so that the example below may be used verbatim\nclass Screen:\n # Create new image, same size as EV3 LCD:\n image = Image.new(\"1\", (178, 128), \"white\")\n draw = ImageDraw.Draw(image)\n draw.rectangle((0,0,177,127))\n \n @staticmethod\n def update():\n return Screen.image",
"execution_count": 1,
"outputs": []
},
{
"metadata": {
"trusted": true,
"collapsed": false
},
"cell_type": "code",
"source": "screen = Screen()\n\n# Draw some eyes:\ndef draw_eye(x, y):\n eye_xrad, eye_yrad = 12, 18\n pup_xrad, pup_yrad = 5, 5\n\n screen.draw.ellipse((x-eye_xrad, y-eye_yrad, x+eye_xrad, y+eye_yrad), )\n screen.draw.ellipse((x-pup_xrad, y-pup_yrad, x+pup_xrad, y+pup_yrad), fill='black')\n \ndraw_eye( 60, 90)\ndraw_eye(120, 90)\n\n# Write some text:\nfont = ImageFont.truetype(\"arial.ttf\", 20)\nscreen.draw.text((10,10), \"Hello world\", font=font)\n\n# Paste an image:\nlogo = Image.open('ev3dev_logo.png')\nscreen.draw.bitmap((130, 10), logo)\n\n# Show the result:\nscreen.update()",
"execution_count": 2,
"outputs": [
{
"output_type": "execute_result",
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAALIAAACAAQAAAACHQw5jAAACIklEQVR4nO2WP2/TQBiHHztubaSg\nWghQB6RcJUaQChMMlY+KgY9RvgEjU+KwsKF+hE58BhbAQZHYUIaOSDiIoeJfLeHBSW0fwzm0F2ya\nikoIKe9yvsc//fz6vffOhoboqboI7Qb5f8sHK1sbTp3ebvJ5LwGbdEoqAZgiwc3oxDX6yQUeilqf\ng9PyHFOIdHR3a/cj4Gb9mX8c5glkcfgBmHiMBTgU3rOofLGa/Xj07R0A2wAO4GMLovvy5vNjf4dW\n9hRgrQJBBvksH8d38AQCGHSs658070R5oq49jokBvlOezL87u8igyjORZWx7ecQh4Ia9UaW/Jd0H\n3Lu4y20A2Q+GmovQ8cETbJwoxHwfvh1yZ+0sfRj1hlUdjJiE+cu0Tu81+FzC9mt8gnG9frBi1fdV\nU54N3I26rbxW/4QGf9ngH9Xz7my9jJhICnH2/H+vzxH9P+iXfMnPg/f1MPFNrl5JAL7sm7wc7ADw\n9arJCzYBGLVMPmUdgD07NHhKG0BJKzK4Vx0jIaY+pgQo0WfoL+7rjWPpzcup7xtjVT7+QvomHr4h\nBLJCZAaXQR/ASQ8W81dEACT5Ys89L25V9fIdkzfpo0EPIG+vJ9UN/X15rUqllDpS6vCv/nMEqpol\nC+kTcgBFVb9jH7uaCYNn6HWa76s2KYAVKWnwVf2XwU5p6luMANgszHzsYA+Ay59Nbm3r/K7cMDk9\nPbjJHJ+PJf+3vCl+AiV2z6xfgLuiAAAAAElFTkSuQmCC\n",
"text/plain": "<PIL.Image.Image image mode=1 size=178x128 at 0x7F93BAF226A0>"
},
"metadata": {},
"execution_count": 2
}
]
},
{
"metadata": {
"trusted": true,
"collapsed": true
},
"cell_type": "code",
"source": "",
"execution_count": null,
"outputs": []
}
],
"metadata": {
"language_info": {
"file_extension": ".py",
"mimetype": "text/x-python",
"nbconvert_exporter": "python",
"codemirror_mode": {
"version": 3,
"name": "ipython"
},
"pygments_lexer": "ipython3",
"version": "3.5.2",
"name": "python"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3",
"language": "python"
},
"_draft": {
"nbviewer_url": "https://gist.github.com/d1f4bf9b9f2ad8494574fd068d8f6248"
},
"hide_input": false,
"gist": {
"id": "d1f4bf9b9f2ad8494574fd068d8f6248",
"data": {
"description": "pillow testbed",
"public": true
}
}
},
"nbformat": 4,
"nbformat_minor": 0
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment