For those who think ‘just install Pillow’:
- Pillow has a lot of dependencies if you are on Linux,and is very big no matter the platform
- An image,is a basic data type,like a ZIP or a JSON,if other basic data structures can be implemented,so can images.
- Most developers do need images at some point.
- Do you really need a venv just to open a image?
Errors:
ValueError - exists in normal Python,used for if you say…make a JPEG with rgba,or if you access the -1st row
UnsupportedFormatError - format isnt a bitmap,a JPEG or a PNG
images.Image
Create a new Image object,always starts with all black
an Image is a 2D iterable,and a pixel is a tuple with integers
resolution → tuple with 2 entries,format → (rgb,rgba,greyscale)
images.open(filename,format(JPEG,PNG,bitmap,auto,default:'auto')) → open a image as a Image object
Image.change_format(format) → (rgb,rgba,greyscale),changes the format of the Image
256 color PNGs are converted to RGBA
Image.save(path+filename,format(JPEG,PNG,bitmap,auto,default='auto')) → saves to the location.
Image.load_tk() → load an Image into Tkinter
Image.rotate(amount) → rotate in 90 degree increments
Image.flip((direction=('h','v',default:'h')) → Flips the image
Image.crop(x1,x2,y1,y2)(if it goes off the image,a warning is done and the off image parts are black) → Crops the image
Image.resize(x,y) → resize from top left(if it goes off the image,the off image parts are black,but no warning)
Image.upscale(x → int,y → int) → upscale image using nearest neighbor scaling,ValueError if x or y <= 0
Image.downscale(x,y) → downscale by removing pixels,ValueError if x or y > width and height of actual image,or negative
Image.downscale_relative(x,y) → same as Image.downscale but relative instead of absolute,ValueError if x or y > 1.0,or negative