Skip to main content

Classes and methods to handle pictures for the web

Project description

Build pypi versions codecov license

Gallerist

Classes and methods to handle pictures for the web, using Pillow.

$ pip install gallerist

Features

  • Code api to handle the generation of pictures in various sizes (e.g. medium size picture, small size, thumbnail)
  • Both asynchronous api and synchronous api
  • Supports user defined stores for binaries, for example to read and write files in Azure Blob Storage, or AWS S3
  • Handles by default JPG, PNG, GIF, MPO; and provides a code api to support adding more supported formats
  • Supports scaling animated GIF files (resized gifs are still animated)
  • Maintains PNG transparencies

See also

Examples

Basic example using the synchronous api, and reading files from file system:

from gallerist import Gallerist
from gallerist.fs import FileSystemSyncFileStore


gallerist = Gallerist(FileSystemSyncFileStore('tests'))


metadata = gallerist.process_image('files/blacksheep.png')

Configuring sizes

from gallerist import Gallerist, ImageSize
from gallerist.fs import FileSystemSyncFileStore


store = FileSystemSyncFileStore("tests")

# configuring sizes by mime (use '*' to match any other mime):
gallerist = Gallerist(
    store,
    sizes={
        "image/jpeg": [ImageSize("a", 500), ImageSize("b", 400), ImageSize("c", 300)],
        "image/png": [ImageSize("a", 350), ImageSize("b", 250), ImageSize("c", 150)],
    },
)

metadata = gallerist.process_image("files/pexels-photo-126407.jpeg")

print(metadata)

The original picture is not modified, it is only read to produce more images in other sizes.

Metadata:

<ImageMetadata width=2520 height=1418 extension=".jpg" mime="image/jpeg" versions=[
  <ImageVersion
    size_name="a"
    id="bbf665ba8dd3412a84ac435a086fc7ad"
    max_side=500
    file_name="a-bbf665ba8dd3412a84ac435a086fc7ad.jpg"
  >,
  <ImageVersion
    size_name="b"
    id="7e4b38b977964c2a91544c1e0621c3a1"
    max_side=400
    file_name="b-7e4b38b977964c2a91544c1e0621c3a1.jpg"
  >,
  <ImageVersion
    size_name="c"
    id="847cad2796004b5086269bec9d705cdc"
    max_side=300
    file_name="c-847cad2796004b5086269bec9d705cdc.jpg"
  >
]>

Implementing a custom file store

Custom stores must implement one of the following protocols:

from gallerist.abc import FileStore, SyncFileStore


class MyAsyncFileStore(FileStore):
    """Implement your async file store, then use gallerist.process_image_async method"""

    async def read_file(self, file_path: str) -> bytes:
        pass

    async def write_file(self, file_path: str, data: bytes):
        pass

    async def delete_file(self, file_path: str):
        pass


class MySyncFileStore(SyncFileStore):
    """Implement your sync file store, then use gallerist.process_image method"""

    def read_file(self, file_path: str) -> bytes:
        pass

    def write_file(self, file_path: str, data: bytes):
        pass

    def delete_file(self, file_path: str):
        pass

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

gallerist-0.0.6.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

gallerist-0.0.6-py3-none-any.whl (8.8 kB view details)

Uploaded Python 3

File details

Details for the file gallerist-0.0.6.tar.gz.

File metadata

  • Download URL: gallerist-0.0.6.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for gallerist-0.0.6.tar.gz
Algorithm Hash digest
SHA256 71a214ac8f39e9f87b0fd098804f2428afd0e4d156da8131ffaadde063d1df61
MD5 57db4365c61f8d51a11d963f72d5d883
BLAKE2b-256 7aa08fbe19e15defeb7362b8c5c5078d9eb146de0d8283b3d3f892c6363548fa

See more details on using hashes here.

File details

Details for the file gallerist-0.0.6-py3-none-any.whl.

File metadata

  • Download URL: gallerist-0.0.6-py3-none-any.whl
  • Upload date:
  • Size: 8.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.0 importlib_metadata/4.8.2 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for gallerist-0.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 437c1c268e8fadc9c5962c9df4bc9e1e8bf7356bd5f38f45223d9d24804b1911
MD5 4d4b716a21247e19c63f7652b6f8ffb0
BLAKE2b-256 6bc49fedf74d10457d8e8d1182cb5f334f8ba2408eb61f672c8bf99f5cd46748

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