A package for image processing utilities using the Picsum API
Project description
Version 1.0.1
- Fixed license link issue.
- Updated README.md
- Fixed typo (pisumphotos) now picsumphotos
Image Utility Package
This package provides utility functions for working with images using the Picsum API. It includes functionalities to validate URLs, fetch image data, generate image URLs with various parameters, retrieve a list of image URLs, and save images to disk.
Features
- Validate URLs: Check if a given URL is valid.
- Fetch Image Data: Retrieve the binary content of an image from a URL.
- Generate Image URLs: Create URLs for fetching images from the Picsum API with various parameters.
- Fetch Image: Get an image from the Picsum API and its binary content.
- Retrieve Image List: Get a list of image URLs from the Picsum API.
- Save Image: Save an image to a specified path from either a URL or raw binary data.
Installation
You can install the package using pip. Make sure you have requests
and urllib3
installed:
pip install requests urllib3
Usage
Validate URL
from image_utils import isValidUrl
url = "https://example.com/image.jpg"
print(isValidUrl(url)) # Output: True or False
Fetch Image Data
from image_utils import getImageBinary
url = "https://example.com/image.jpg"
binary_data = getImageBinary(url)
Generate Image URL
from image_utils import createUrl
url = createUrl(width=800, height=600, seed="example", blur=5, grayscale=True)
print(url) # Output: Constructed URL with specified parameters
Fetch Image
from image_utils import getImage
image_url, binary_data = getImage(width=800, height=600, seed="example")
print(image_url) # Output: Image URL
Retrieve Image List
from image_utils import getImageList
image_urls = getImageList(limit=10)
print(image_urls) # Output: List of image URLs
Save Image
from image_utils import saveImage
image_url = "https://example.com/image.jpg"
# Or
image_url = "binary_image_data"
saveImage(imageDataOrUrl=image_url, path="path/to/directory", fileName="image", imageFormat="jpg")
Functions
isValidUrl(url: str) -> bool
Verifies if the provided URL is valid by checking if it contains a scheme and a host.
getImageBinary(url: str) -> bytes
Fetches the binary content of an image from a given URL.
createUrl(width: int, height: int, seed: str = None, picId: int = None, blur: int = None, grayscale: bool = False) -> str
Generates a URL for fetching images from the Picsum API with optional parameters.
getImage(width: int = 200, height: int = 200, seed: str = None, picId: int = None, blur: int = None, grayscale: bool = False) -> tuple
Fetches an image from Picsum API and returns both its URL and binary content.
getImageList(limit: int = 30) -> list
Retrieves a list of image URLs from the Picsum API based on the specified limit.
saveImage(imageDataOrUrl: str, path: str, fileName: str, imageFormat: str, secure: bool = True) -> None
Saves an image either from a URL or raw binary data to the specified path.
Notes
- Ensure that
path
insaveImage
is a valid directory path. - The
secure
flag insaveImage
helps in warning about untested image formats
License
This package is licensed under the Apache2 License. See the LICENSE file for details.
Contact
For any questions, please reach out to packages@escapedshadows.com.
Disclaimer
I do not own any rights to the provided License file; all rights are owned by the Apache Foundation. Additionally, I am not affiliated with picsum.photos in any way. This package is a community-driven project designed to simplify interaction with the picsum.photos API directly from your Python Script.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file picsumphotos-1.0.1.tar.gz
.
File metadata
- Download URL: picsumphotos-1.0.1.tar.gz
- Upload date:
- Size: 8.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e9cd9e0d6d243f5a1bfb89b70c5aa8b1c47bb3546dac8868f9eb05da2f7d176 |
|
MD5 | d4085e832b584c3e4876ac82e60d2b48 |
|
BLAKE2b-256 | b88c575c9094ffb678a527c046bc9deb0389c11d23073b97b395a7f225042dfb |
File details
Details for the file picsumphotos-1.0.1-py3-none-any.whl
.
File metadata
- Download URL: picsumphotos-1.0.1-py3-none-any.whl
- Upload date:
- Size: 9.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a34c5b5cbb70f2d3befde4853191a9c3141fce1c8127d2bcf899aa96c9845c61 |
|
MD5 | 969d62ad27593bcdd8910c2e688e8505 |
|
BLAKE2b-256 | a75a865cc178f7ca297f4e234a15b4dc5630b5e32e1907927583a12902cd189d |