{
 "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": "[encoded data, 552488 characters]\n",
      "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": "[encoded data, 281296 characters]\n",
      "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": "[encoded data, 40156 characters]\n",
      "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": "[encoded data, 19016 characters]\n",
      "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": "[encoded data, 439580 characters]\n",
      "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+3vOee2YtumxDP351rW3JvWJYaoxMQWQBGNeIwRjBiGCMoLU+Y4zOi9KjYtSYEtl++IefGQE0YDq9v9XJhx7ZenTuREF+JGI+ZWFcHzQMXHtN7tfaG9XF0lcPb/rCPsDrREhqAY9sPTq3VJRhy1iDaYHj+kVJaaJw+anjP3tyB1AEJA2PnVZAOc8G21iDGK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lEyBfU6et57/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
}
