Skip to main content

A package for image processing utilities using the Picsum API

Project description

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 in saveImage is a valid directory path.
  • The secure flag in saveImage 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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

picsumphotos-1.0.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

picsumphotos-1.0.0-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file picsumphotos-1.0.0.tar.gz.

File metadata

  • Download URL: picsumphotos-1.0.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.2

File hashes

Hashes for picsumphotos-1.0.0.tar.gz
Algorithm Hash digest
SHA256 162b05134146801ccea6bd9388cf74e5a95871e694afe24e28f65eb33dc289a9
MD5 20b1d35bbbcff3a4c7ecc238bb68faea
BLAKE2b-256 ddb66eda925587a7d2364949d9c14cf1b5eb8b8454b19069990918e91176159d

See more details on using hashes here.

File details

Details for the file picsumphotos-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for picsumphotos-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 550897dcd9f123247663dda0d5fb10ad0e7734687b9b007a04e4adf2a864aa9e
MD5 160ac64ffc8644fbf7465bccdc6c35af
BLAKE2b-256 4e05928efad691533aec6ec5c19cdd6b9389dc49cdc06af6aac958f0facf7ea1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page