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.

7.0 KiB

PIL(low) talk

The "classic" Python Image Library (or PIL) is described in the (classic) handbook: http://www.effbot.org/imagingbook/pil-index.htm

In fact, the current library that people tend to use is called Pillow, 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:

https://pillow.readthedocs.io/en/stable/reference/index.html

In [ ]:
from PIL import Image
In [ ]:
im = Image.open("camera128.png")
In [ ]:
im
In [ ]:
im = Image.open("1024px-IBM_Keypunch_Machines_in_use.jpg")
In [ ]:
im.size
In [ ]:
im.mode
In [ ]:
im.thumbnail( (320, 320) )
In [ ]:
im.size
In [ ]:
im
In [ ]:
from urllib.request import urlopen
In [ ]:
f = urlopen("https://upload.wikimedia.org/wikipedia/commons/1/10/NOLAPunchCards1938.jpg")
In [ ]:
key2 = Image.open(f)
In [ ]:
key2.size
In [ ]:
key2.convert("1")
In [ ]:
key2.thumbnail((1024, 1024))
In [ ]:
key2.save("keypunch.png")
In [ ]:
key3 = Image.open( urlopen("https://upload.wikimedia.org/wikipedia/commons/thumb/4/48/IBM26.jpg/1024px-IBM26.jpg") )
In [ ]:
key3.size
In [ ]:
key3.convert("1", dither=Image.NONE)
In [ ]:
key3
In [ ]:
key3.convert("L")
In [ ]:
key3 = key3.thumbnail((64, 64))
In [ ]:
key3 is None
In [ ]:
from PIL import ImageDraw
In [ ]:
gray.save("keypunch_gray.png")
In [ ]:
key2.convert?
In [ ]:
import aalib
In [ ]:
screen = aalib.AsciiScreen(width=640, height=480)
In [ ]:
f = urlopen('https://www.python.org/static/favicon.ico')
In [ ]:
im = Image.open(f)
In [ ]:
im
In [ ]:
im = im.convert('L').resize(screen.virtual_size)
In [ ]:
im
In [ ]:
screen.virtual_size
In [ ]:
screen.put_image((0, 0), im)
In [ ]:
print (screen.render())
In [ ]:
resized = key2.convert("L").resize(screen.virtual_size)
screen.put_image((0, 0), resized)
In [ ]:
screen.render()
In [ ]:
resized
In [ ]: