{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# `PIL.Image` Demo\n", "\n", "PIL is the **Python Image Library**, and has excellent\n", "[documentation](https://pillow.readthedocs.io/en/latest/index.html).\n", "\n", "This is a simple demonstration of rendering PIL images in a `jupyterlite` notebook. Most\n", "of PIL should work as designed." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import the Library\n", "\n", "`jupyterlite` comes with PIL, so you only need import what you need from it." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from PIL import Image" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create a new Image" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image = Image.new(\"RGB\", (100, 100))\n", "image" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Saving an Image" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "image.save(\"box.png\")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Open an existing Image\n", "\n", "Currently only works with images written by `jupyterlite`." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "box_image = Image.open(\"box.png\")\n", "box_image" ] } ], "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.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }