You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

694 lines
1.3 MiB
Plaintext

{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# PIL(low) talk\n",
"\n",
"The \"classic\" Python Image Library (or PIL) is described in the (classic) handbook:\n",
"http://www.effbot.org/imagingbook/pil-index.htm\n",
"\n",
"In fact, the current library that people tend to use is called [Pillow](https://pillow.readthedocs.io/en/stable/), but as a \"friendly fork\" it tries to acts just like the old PIL library, so you don't even notice (and your code still uses the name PIL). The Pillow project also maintains it's own documenation at:\n",
"\n",
"https://pillow.readthedocs.io/en/stable/reference/index.html\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from PIL import Image"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"im = Image.open(\"a.jpg\")"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAuQAAAR7CAIAAABHJiaeAAEAAElEQVR4nOz92ZIkyXIditrk7jFmZlV1dWOjBcCGkAQPn/j/f0EREODBHgDu3kOPVTlExuDuNpyH5WuFRjYO5d77cg/v7Xhoqc6MjDA3U1NdqrpU1f/5T99cLpdSive+1uq9Tyl570MIXdeVUsZxbK0Nw+Ccm+c5hJBSSilN03Q6nVpr+MNSSq3VOdd13Wq16rqutVZrnaap73vn3DiOpZQYo/c+5zwMA/4kxphSCiGUUnLOrbWu62qt5/P58fFxnueHh4fVarVarfq+jzHWWvE2fOlqtaq11lrxE+dcCCHGOI5j3/f46nmeSyn4Od6cUhqGAV+Kp9afe++dc/gW/KS1Nk1TrbXruhhjay2EgHfO8zxNU0ppvV631s7ns3Nus9l0XadnCSHknLFj5/MZz4sN+fTp07fffjsMw1dffbXdbvHJ+DTnXIwx54x/TNOEh22t9X3vvR/HcZ5nPK9zruti4wtrCyF473OuIQQcBDYBD9h1H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Eh34cR0BGLVI6EOKn1FVrTYBMkWNvPBNsjvU3JFen00lq2TPXX2tdrVYQgMj4n9BMvY2gwI3OOSsujjdL6vC2zWYDmcEpwGhBGIROOubT8ZJzDwkvDJDIfOB7sYfQGPg0KH85No7o/9ZlX+AOtgs5CBhFfSDORSeLb8Sfw2m3VhMS0jHRryuPLY0xwgZDooAbEL4tzNlJWWFtCk5jT/C/2+3Wxt2r8R6hSXa7HQQYd00JskAADYkSJUPBJx7ERfoqMGcH1C4gK9dauF+iqwyXQKQiaohEQh15xt48cTbMgdXAjcER7QzistD8FnMnRVA
"text/plain": [
"<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=740x1147 at 0x7FF9140ED400>"
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"im"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
"im = Image.open(\"cyber.jpg\")"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(500, 488)"
]
},
"execution_count": 7,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"im.size"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"'RGB'"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"im.mode"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"im.thumbnail( (320, 320) )"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(320, 312)"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"im.size"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAUAAAAE4CAIAAAClg71RAAAKMWlDQ1BJQ0MgUHJvZmlsZQAAeJydlndUU9kWh8+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ID0+6j068GDBgztj3LEnP2X/9H686CH5YcWEzkTzI9tHxyZ9Jy8/Xvh4/EnWk5mnxT8r/1z7zOTZd794/DIwFTs1/lz0/NOvm1+ov9j/0u5l73TY9P1XGa9mXpe8UX9z4C3rbf+7mHcTM7nvse8rP5h+6PkY9PHup4xPn34D94Tz+6TMXDkAAQAASURBVHicNP3Xj21blt6JTb/8WtvvHT7ixPHXp7mVmZVlmFVJssgGGxTRoiz4DxB6EaAHvQh6kAQCDQiSGmojoaUW0C2xu4sUTXdWZbGYVelv3pvXHn9O+Igd2++9/JpeD5f6ByYwgQ8DY47xfb8JT756WVVVt9edL6aMscFWdzFfeDQAFqtGrdLZcDvGxKabfL5cMBZ1O13Hx0EQCUnKsnIYrOuySAuKvE63BRzHQAeClWpqbZMwRhcnb8rNMp+WsUv9Tpu2gi8//exbH3y4c+d4UxXWAIc54+vxoN83wFCKRNMYaXktw7aPiGs0ALCGVsi65o2Mkh5AVBqDkKWEIECvL26GvZ6CSjsQQhdoky/WvsMAAY5HhRDQIKuBE7iEIAghQlBbYyFACBoNIcRaNxBroKw22nGJybM0nXPgCOmIUj18/PD66rwsspo3d+7f3Yyns8m01e1CALTWddMc3Tn66ulXv/O977iBN18tRCNcRKuqTtothKBQqpGCQqqloi6Tmrf86Fe/+OXuzm6
"text/plain": [
"<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=320x312 at 0x7FF91406B748>"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"im\n"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"from urllib.request import urlopen"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"f = urlopen(\"https://upload.wikimedia.org/wikipedia/commons/1/10/NOLAPunchCards1938.jpg\")"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [],
"source": [
"key2 = Image.open(f)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(600, 458)"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"key2.size"
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAAlgAAAHKAQAAAAD3WwikAAB1a0lEQVR4nG19eVgT1/f+O8MEBnAZIihVKwMGRXCr1WpblwGxDahtxAxQcEFrW4WidHGpqAwU/aBdRAS12tZowUICQq0sLpC4tLWuaAUURKJ1QRCICiSS5f7+sPv3d/5JnmfIm/ece86955x7uaEUm/CHUAWRVt2iNwHKyZaa+bQbVOCbmwB4PvS5EXUQ9Gv1X81AfjSEk/YEgaqRnn1KkvAXQBbKe/3xPi5P1V0yVkLgMPrKJk0Z49CR2m+NkFknBMz6vmTzvoRr2+H5kCJu++TPubxtePZ5HyMgs0LUAQgXA3MCtVqtVqutWZozxy/X1xUKCIw/I/HaKzzNIS13obktLHxxkX9ZGsOHCqyv2H60CJIvJ/myGVlcCCfxIWBDOErs7AWgf4vdCV7hOdbzScw6OuXq1YCeGtOHo47sdoQ4n8wYcfLp6PUBj7htidduEcYm1VK7Nma7meBitdGvPf3llYudjJ/5/iRKsQk6OPcs7AZFB8y+KfFxvBHKigx7MmTq+2cmGSATvZbe8akGs/L1/pIkgb/FquiUYQi+fw38+FlxACSJM4GmsspvjAUoUQtQS+q710w1UH3pXfF9PN40/PKOXGIt9NCffjuR1Ou1lrGvBp+9I/Xps3jTUzHqxxNNbt28kUbKpzbQDolZB1DiHwOiiYPHwJWReLzV6QbUD+d8lL7Gf+ssKZUjj4++6GinZ7uzD+c4SwDtAET8uCZrTN9xP08KjLH53vduZjHecZEKcxcLnw2jPTnf2KmfdLrXY+GNj4X5C9k+VVNJB9j173wWbsAng3fv3NZvOBcHSWCOAxDq3e5Y3NyDEPpNE3/bAXYSc8P/YVcc3LsAarN6Qks5Z+MmGdy+3OgpGLfcWC4pB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RdO593L63whuf7nhhIIBgDSmVnheP4YKRXqtn583MBomLj9rTqVZQ0gZZooWQ+o8DggSJKpgiTIXlvctyOMrUtNbS2bXx/xMLKj5d6BQ/YY2HyBWxwXoDM8HVWtxZMK0EP4asyouTbMdiMz8zYhfLP1+2ZKBODMtQAAYndVUJh+nP363YE3eKopdsD0rkLNnTKp08aAsWRvnbTddRV6j13F32qiHeHWxk/Tr2//7JbT5NN2p3Ub3xGoQAmAU350flccECmctv3w9peb0u59SFxsB2CM+6nQ7xQEdg3429j+1i8WV74uX0c7WIu8j2zM8bVu7yuP21hv5gZSJ/jTzYC7Li+Vhbuu0IHTn8t2vv+u3/eZQ1wsg1ujTiQciBl31JC5RhKMfm9+cSHw1wl33RDizHpntq9tCx7XU6S6PpizxN2AIjP3EkXPBRUxX1QFSYD1chN4KX5SvycVkuFWk9v/rnLCkf/FPdTTfZ/Y6Rl07i+BGyzw6q/hhVSXMPPiOs2TLjOCm24R5aTUeBOFLG8SRakBANFzORPE1ge25NtptvQNfsbcNkOc1tZ16LUKpG/StL770Xo42c7NBADezfKijttWPH49oeneHQhdVgneTZvrJ4gJy0RRe5ihmI2qjYwXzYIFRwV7+sbUtrTlcwAH/+6wBV3r509YWL+ZYpgMCts8Xf1CBCgBDjRDt2gpmYoUwk1nybdHO2kfwGhUt9/7tCuO8jHC86F7l9jfZF3wuSGsnOs+8u6VCltIs3FfYCa4W8TPj+khzXW+Ta4uY3GGfTR+DeiYVEBMFEUxMK9AxYDLZ5lIFgqKTXVSzmb61xdZl7JpoIOdanI29DjKP65vFQRIPIuxgZ77pSwGPAVGEDLqaygvboz9asaoajjaTsQ9XMDYhLTmR7L9VeCbLak5Wxbnj6xzOZ9p4o2yT4aPu2Yb1yW+OPGDqScdQrCBe3LBc5CBWWc46QAQOAxswRyBNq/KSww
"text/plain": [
"<PIL.Image.Image image mode=1 size=600x458 at 0x7FF91402F0B8>"
]
},
"execution_count": 21,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"key2.convert(\"1\")"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\u001b[0;31mSignature:\u001b[0m \u001b[0mkey2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconvert\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmode\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmatrix\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdither\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpalette\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcolors\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m256\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDocstring:\u001b[0m\n",
"Returns a converted copy of this image. For the \"P\" mode, this\n",
"method translates pixels through the palette. If mode is\n",
"omitted, a mode is chosen so that all information in the image\n",
"and the palette can be represented without a palette.\n",
"\n",
"The current version supports all possible conversions between\n",
"\"L\", \"RGB\" and \"CMYK.\" The **matrix** argument only supports \"L\"\n",
"and \"RGB\".\n",
"\n",
"When translating a color image to greyscale (mode \"L\"),\n",
"the library uses the ITU-R 601-2 luma transform::\n",
"\n",
" L = R * 299/1000 + G * 587/1000 + B * 114/1000\n",
"\n",
"The default method of converting a greyscale (\"L\") or \"RGB\"\n",
"image into a bilevel (mode \"1\") image uses Floyd-Steinberg\n",
"dither to approximate the original image luminosity levels. If\n",
"dither is NONE, all values larger than 128 are set to 255 (white),\n",
"all other values to 0 (black). To use other thresholds, use the\n",
":py:meth:`~PIL.Image.Image.point` method.\n",
"\n",
"When converting from \"RGBA\" to \"P\" without a **matrix** argument,\n",
"this passes the operation to :py:meth:`~PIL.Image.Image.quantize`,\n",
"and **dither** and **palette** are ignored.\n",
"\n",
":param mode: The requested mode. See: :ref:`concept-modes`.\n",
":param matrix: An optional conversion matrix. If given, this\n",
" should be 4- or 12-tuple containing floating point values.\n",
":param dither: Dithering method, used when converting from\n",
" mode \"RGB\" to \"P\" or from \"RGB\" or \"L\" to \"1\".\n",
" Available methods are NONE or FLOYDSTEINBERG (default).\n",
" Note that this is not used when **matrix** is supplied.\n",
":param palette: Palette to use when converting from mode \"RGB\"\n",
" to \"P\". Available palettes are WEB or ADAPTIVE.\n",
":param colors: Number of colors to use for the ADAPTIVE palette.\n",
" Defaults to 256.\n",
":rtype: :py:class:`~PIL.Image.Image`\n",
":returns: An :py:class:`~PIL.Image.Image` object.\n",
"\u001b[0;31mFile:\u001b[0m ~/.local/lib/python3.7/site-packages/PIL/Image.py\n",
"\u001b[0;31mType:\u001b[0m method\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"key2.convert?"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": [
"key2.thumbnail((1024, 1024))"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [],
"source": [
"key2.save(\"keypunch.png\")"
]
},
{
"cell_type": "code",
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
"key3 = Image.open( urlopen(\"https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/IBM26.jpg/1024px-IBM26.jpg\") )"
]
},
{
"cell_type": "code",
"execution_count": 37,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(1024, 683)"
]
},
"execution_count": 37,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"key3.size"
]
},
{
"cell_type": "code",
"execution_count": 25,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABAAAAAKrAQAAAABHbcI5AAA3fElEQVR4nO29fZQkV3ke/lRVa6olRuo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4E2beL4ELEWYG/70gAUAZsTamjI72Ztq82pA+gYZpqVQbfLGLbPIyFa474RB+mRAkqEYsw22CbQTQI8pyW4Xmd7Yf9Nx4GjGrZC7Lyt7f1OUXaYhVSJxzzNIkvuzfagc6btmAUBFu5MHo0cSJNdYUqOS80lNKFcF4+f80X/SBHhUsz9c7nZDa1oATSjX63yvQ4b4/zbphhkFZUPfNhMOyHCeZ4tBurlnMVHik60Lvvct34YmtL+0Sx6eO1E6k1GeKTbgALjFe+6vF8O8YBPzh+blXlbj32s2ISMVQ1QAECtTnFfa3GudmjTCBgCmN6KRA9CdOhHgjDiHyONo+mG2CeVKwGoey541DABqEbyp8pgmsQo1aIRtST+wx0W6oSmCHICaKJ0yJ1wOa5Vj0O6XncYBUM7GXWe8nrRbdTrQ95pBSEipUNsThoQPbkCdx8WMAJjTXttTGsVllFWBcmlhTb1PbDfQ+csAqJl9MWX+cDCBxo16P7av7T+npUg9r5mVgHpD+DIbwPTLPypMppcBKKkf9/KgVnGmhkadGhY2A6DuaV3EI82+6QBgqJfugJKS8tqasEdywYpeHpgSQ7a6UZJyfRn2yfB51oRy9TKNF9EoW0oIAPOvP7f8WyoRTQbArk3AuvzcTpgFqngZAE8RIurGO0XdYqzBFoIKQEauCoDfJ4Pd8XykyccDazyCseQo3A2/RwZBBuAfSAJNL6NKq6BmwGTBu/13JCPGDGT
"text/plain": [
"<PIL.Image.Image image mode=1 size=1024x683 at 0x7FF91402F9E8>"
]
},
"execution_count": 25,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"key3.convert(\"1\", dither=Image.NONE)"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"key3"
]
},
{
"cell_type": "code",
"execution_count": 38,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAABAAAAAKrCAAAAABKfaBIAAEAAElEQVR4nJT9SZMs25YmCH3f2lvVzJvjp7nd65vIyIisyKrMkqREQASBGpXAiC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/+tPXx2vjPDOrDG0zkkckZmXwb1/qFOuC2m3/7gvoK3oBJTrDa/373+nSYmqs/2nAw8ELqML1X3WAGe8KDY/HBL76AOJ1BsEXTEvUi/sdIKzzJFEiaqe0ZYQnhqQGkTYTE7ga1Rnd5Oj4iCt4fT/ZLyDh7279ty9erL83Rdnn26XLRqDQGFE/YCtoRADuTQIIHeA/8U70MCooF6FavbkPrHGZERXOYTjRsurkgHOoc2gB8nI/Lq/Fp9L+zeHSbzFNQSUVH8o7S8WTyRGwX9P+qw/uT9fHBOztgNFmS5DMvMVhCwnBqDyNV/j6H+zfPtvfQzN2I0hobvJzRNiFhAtIq2tXLTBupCRyRw6uZMXSybPqzEFzzVcHjA/X9V+9fnk3HTjgxTxNZsYDQCVodiSKqSSIphLgK6UEcML+J8Nu0LDzg4W8Ufr4X7/85urf+Z/97OMflV98c/i6/vRj+9Tz8UYcKIxqXOEkUq5lX4uT1iAemzffWNoO1lDGqmGSK7Xoe9zfgnMghhD1rM2oaApZqdvWLRaf3GnyembTS7LgBqWIasgBkqDLFT5kpk5UW+s1C5JDqYkbVwiDsLEXZ/wqKhbmD6Nw2oJ0EQO0Ae/q74vvUDCes9+Sf4ANrCVZ49ULgrE2huY0jvwDipVh1W2s8eW/3KywAErSAEAu5XMwhWImyUyMdA9v41++v8wghpnlPXEj/Hh9STw4aCfJ29S
"text/plain": [
"<PIL.Image.Image image mode=L size=1024x683 at 0x7FF914035DA0>"
]
},
"execution_count": 38,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"key3.convert(\"L\")"
]
},
{
"cell_type": "code",
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
"#key3 = key3.thumbnail((64, 64))"
]
},
{
"cell_type": "code",
"execution_count": 39,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"False"
]
},
"execution_count": 39,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"key3 is None"
]
},
{
"cell_type": "code",
"execution_count": 40,
"metadata": {},
"outputs": [],
"source": [
"from PIL import ImageDraw"
]
},
{
"cell_type": "code",
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
"key3.save(\"keypunch_gray.png\")"
]
},
{
"cell_type": "code",
"execution_count": 42,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"\u001b[0;31mSignature:\u001b[0m \u001b[0mkey2\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconvert\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mmode\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mmatrix\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mdither\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;32mNone\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mpalette\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mcolors\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m256\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
"\u001b[0;31mDocstring:\u001b[0m\n",
"Returns a converted copy of this image. For the \"P\" mode, this\n",
"method translates pixels through the palette. If mode is\n",
"omitted, a mode is chosen so that all information in the image\n",
"and the palette can be represented without a palette.\n",
"\n",
"The current version supports all possible conversions between\n",
"\"L\", \"RGB\" and \"CMYK.\" The **matrix** argument only supports \"L\"\n",
"and \"RGB\".\n",
"\n",
"When translating a color image to greyscale (mode \"L\"),\n",
"the library uses the ITU-R 601-2 luma transform::\n",
"\n",
" L = R * 299/1000 + G * 587/1000 + B * 114/1000\n",
"\n",
"The default method of converting a greyscale (\"L\") or \"RGB\"\n",
"image into a bilevel (mode \"1\") image uses Floyd-Steinberg\n",
"dither to approximate the original image luminosity levels. If\n",
"dither is NONE, all values larger than 128 are set to 255 (white),\n",
"all other values to 0 (black). To use other thresholds, use the\n",
":py:meth:`~PIL.Image.Image.point` method.\n",
"\n",
"When converting from \"RGBA\" to \"P\" without a **matrix** argument,\n",
"this passes the operation to :py:meth:`~PIL.Image.Image.quantize`,\n",
"and **dither** and **palette** are ignored.\n",
"\n",
":param mode: The requested mode. See: :ref:`concept-modes`.\n",
":param matrix: An optional conversion matrix. If given, this\n",
" should be 4- or 12-tuple containing floating point values.\n",
":param dither: Dithering method, used when converting from\n",
" mode \"RGB\" to \"P\" or from \"RGB\" or \"L\" to \"1\".\n",
" Available methods are NONE or FLOYDSTEINBERG (default).\n",
" Note that this is not used when **matrix** is supplied.\n",
":param palette: Palette to use when converting from mode \"RGB\"\n",
" to \"P\". Available palettes are WEB or ADAPTIVE.\n",
":param colors: Number of colors to use for the ADAPTIVE palette.\n",
" Defaults to 256.\n",
":rtype: :py:class:`~PIL.Image.Image`\n",
":returns: An :py:class:`~PIL.Image.Image` object.\n",
"\u001b[0;31mFile:\u001b[0m ~/.local/lib/python3.7/site-packages/PIL/Image.py\n",
"\u001b[0;31mType:\u001b[0m method\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"key2.convert?"
]
},
{
"cell_type": "code",
"execution_count": 46,
"metadata": {},
"outputs": [
{
"ename": "ModuleNotFoundError",
"evalue": "No module named 'aalib'",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-46-912cb9847582>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0;32mimport\u001b[0m \u001b[0maalib\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mModuleNotFoundError\u001b[0m: No module named 'aalib'"
]
}
],
"source": [
"import aalib"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import aalib"
]
},
{
"cell_type": "code",
"execution_count": 44,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'aalib' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-44-f44aedee4649>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mscreen\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0maalib\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mAsciiScreen\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mwidth\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m640\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0mheight\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;36m480\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'aalib' is not defined"
]
}
],
"source": [
"screen = aalib.AsciiScreen(width=640, height=480)"
]
},
{
"cell_type": "code",
"execution_count": 47,
"metadata": {},
"outputs": [],
"source": [
"f = urlopen('https://www.python.org/static/favicon.ico')"
]
},
{
"cell_type": "code",
"execution_count": 48,
"metadata": {},
"outputs": [],
"source": [
"im = Image.open(f)"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [
{
"data": {
"image/png": "iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAABXAvmHAAAHo0lEQVR4nLWafYxUVxmHn3vn7u6FZQnf0LINpojQiE0LCZY2RuGf1phtrdha1NrEj5I0TSVWGxQ1pvWzMcYQ0FQSC0lFEkXUFBUKxBQQ0I24mjRdKLHbssBQGPmaj517znv84975uHPvnZk7U05yM9lzZuY+v/P+3vOee2YtumxDP351rW3JvWJY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wVrQqheDr9iwR+GCsYjNz7T81eKVyuw5NfO/ZF2Ucv1CV0/B08r8SFuC+fnDl3fOnZ77d18OKSjSqZ/qxORK2mWidu3Bx4uAvXi7v/u42OQOMAVmCLcKNFFAVAcwE5v7rt0s/Mm+2vaLPkZt6e81clIfjmFm2kRnK88a1eHlEyBfU6et57/zIKW/kE18vnsavujn87cFlfPukWoU6FVD5rBMImYxfRfupbUEy+D9CZPATU+GvMBP4s1wIBBSCvzsqBP8HKSkZ+yGrD/oAAAAASUVORK5CYII=\n",
"text/plain": [
"<PIL.IcoImagePlugin.IcoImageFile image mode=RGBA size=48x48 at 0x7FF91401ED68>"
]
},
"execution_count": 49,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"im"
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [
{
"ename": "NameError",
"evalue": "name 'screen' is not defined",
"output_type": "error",
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
"\u001b[0;32m<ipython-input-50-235f2c5973fa>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mim\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mim\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mconvert\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m'L'\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mresize\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mscreen\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mvirtual_size\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
"\u001b[0;31mNameError\u001b[0m: name 'screen' is not defined"
]
}
],
"source": [
"im = im.convert('L').resize(screen.virtual_size)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"im"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"screen.virtual_size"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"screen.put_image((0, 0), im)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"print (screen.render())"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"resized = key2.convert(\"L\").resize(screen.virtual_size)\n",
"screen.put_image((0, 0), resized)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"screen.render()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"resized"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
}
},
"nbformat": 4,
"nbformat_minor": 4
}