Python is a versatile programming language that can be used for a lot of tasks. In this tutorial we will see how we can resize images with Python.
We will use the popular library Pillow for this. Pillow is a fork of the erstwhile PIL library for image manipulation.
In this tutorial we will see how we can resize images using Pillow and we will also talk about a common pitfall while using it.
Time codes:
---------------
00:00: Introduction
00:33: Introduction to Pillow
01:04: Resizing the image
06:51: Caution with Aspect ratio
08:00: Conclusion
Links:
-------
Pillow Github - github.com/python-pillow/Pillow
Pillow PyPi - pypi.org/project/Pillow/
Python Documentation - docs.python.org/3/
Other image manipulation libraries in Python:
OpenCV
Scikit-image
Social Media:
-----------------
Twitter - twitter.com/durgaswaroop
Medium - medium.com/@durgaswaroop
Youtube - / @durgaswaroopperla
Linkedin - www.linkedin.com/in/durgaswaroop/
Video Summary:
---------------------
Using Pillow, we can resize images in Python. Pillow can be installed from the PyPi server using "pip install pillow".
We will use an image of Mt. Fuji of Japan to resize. We load the image with Image.open.
We can display the image with image.show.
We can get the dimensions of the image with image.size.
We can resize the image with image.resize.
Resize function only takes a tuple of width and height. Without that we will get a ValueError.
Resize function also doesn't have any safeguards against aspect ratio changes. So, we need to make sure that the width and height passed in maintain the
Original proportions of the image. Otherwise it will either get skewed and squished or stretched.
Attributions:
---------------
Thumbnail Mt. Fuji - Photo by Tirachard Kumtanom from Pexels
Keyboard sounds - CC Attribution 3.0 License - By Anton from from freesound
(freesound.org/people/Anton/sounds/137/)
Background Music - A New Orleans Crawfish Boil - Unicorn Heads - Youtube Audio
Lucky Cat - Video by Miguel Á. Padriñán from Pexels
Pillow Logo - Pillow Github page - github.com/python-pillow/Pillow
Mt. Fuji - Free for commercial use - Image by K. Mishina from Pixabay
Tools/Gear:
---------
Operating System - Windows 10
Python IDE - Pycharm
Video Editor - Shotcut
Audio Editor - Audacity
Thumbnail Editor - Canva
コメント