The PILTools module¶
The base PILTools module includes a few utility functions that can help with opening and handling images from PIL.
Example: Open an image from the internet into PIL¶
import PILTools
image = PILTools.open_image(url="http://example.com/image.png")
# Note: http://example.com/image.png isn't actually an image it is just there for example purposes
Functions¶
-
open_online
(url, mode='RGBA', size=None, resize_type=3)¶ Fetches an image from the internet and then loads it into PIL. (requires requests lib)
Note: For a async version of this function refer to
async_open_online()
- Parameters
url (str) – The source URL for the image. HTTP(S) supported, other forms may not work.
mode (str) – The PIL mode to load/convert the image to.
size (tuple) – The size to scale the image to. Leave as None to just keep the original image size.
resize_type (int) – Optional resampling filter for resize if
size
defined.
- Returns
The loaded image as a PIL Image class.
- Return type
PIL.Image.Image
- Raises
InvalidImageURL()
if the module cannot read any image data from the given URL.
-
async_open_online
(url, mode='RGBA', size=None, resize_type=3)¶ Asynchronously fetches an image from the internet and then loads it into PIL. (requires aiohttp lib)
Note: For a non-async version of this function refer to
open_online()
- Async
- Parameters
url (str) – The source URL for the image. HTTP(S) supported, other forms may not work.
mode (str) – The PIL mode to load/convert the image to.
size (tuple) – The size to scale the image to. Leave as None to just keep the original image size.
resize_type (int) – Optional resampling filter for resize if
size
defined.
- Returns
The loaded image as a PIL Image class.
- Return type
PIL.Image.Image
- Raises
InvalidImageURL()
if the module cannot read any image data from the given URL.