Skip to main content

cloudstorageimageresizer

A python module to import, rotate, crop and resize pictures into Google Cloud Storage

DISCLAIMER

THIS IS NOT AN OFFICIAL GOOGLE MODULE.

Synopsis

Typical usecase: fetch a bunch of image and generate thumbnails of various sizes for each of them, stored in Cloud Storage for further delivery via a CDN.

from cloudstorageimageresizer import ImageResizer

# Initialize an ImageResizer:
i = ImageResizer()

urls = [
    'http://www.gokqsw.com/images/picture/picture-3.jpg',
    'http://www.gokqsw.com/images/picture/picture-4.jpg'
]

for url in urls:

    # Fetch image into memory and store it in original format to a Google Cloud
    # Storage bucket
    i.fetch(url).store(
        in_bucket='my-images',
        key_name='image-original'
    )

    # Apply the image EXIF rotation, if any
    i.orientate()

    # Resize this image, store it into a Google Cloud Storage bucket and return its url
    url1 = i.resize(
        width=200
    ).store(
        in_bucket='my-images',
        key_name='image-w200'
    )

    # Do it again, with a different size
    url2 = i.resize(
        height=400
    ).store(
        in_bucket='my-images',
        key_name='image-h200'
    )

More explanation

For method parameters, see the code (there isn't much of it ;-)

ImageResizer does all image operations in-memory, without writing images to disk.

The ImageResizer instance is immutable: its internal image is never modified. Each image operation instead returns a clone of the ImageResizer loaded with the modified image. This allows you to chain image operations, and manipulate the same image in different ways without having to explicitely keep a backup copy of it.

ImageResizer uses PIL, has reasonable defaults for downsizing images and handle images with alpha channels nicely.

All images are stored in png format to preserve transparency.

Installation

cloudstorageimageresizer requires Pillow, which in turn needs external libraries. On Ubuntu, you would for example need:

sudo apt-get install libjpeg8 libjpeg8-dev libopenjpeg-dev

Then

pip install cloudstorageimageresizer

Testing

Add your JSON Google API credentials in the file gcloud-credentials.json, edit the BUCKET_NAME in example.py and run it:

python example.py

PEP8

The project follows the PEP8 convention.

It uses flake8 to check the code. If you've installed the dev-dependencies then you can just run the flake8-command and it'll tell you what needs to be fixed if applicable.

Source code

https://github.com/erwan-lemonnier/cloud-storage-image-resizer

Author and contributors

Erwan Lemonnier
github.com/pymacaron
github.com/erwan-lemonnier
linkedin.com/in/erwan-lemonnier/



Johan Wänglöf
github.com/jwanglof
linkedin.com/in/johan-w%C3%A4ngl%C3%B6f-09076192/

Metadata

Release files for google-cloud-storage-image-resizer 2.37.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for google-cloud-storage-image-resizer 2.37.0
File Size Uploaded
google-cloud-storage-image-resizer-2.37.0.tar.gz 6.5 kB Details

Release files / google-cloud-storage-image-resizer-2.37.0.tar.gz

Download URL google-cloud-storage-image-resizer-2.37.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
c28005caf93fc99c6013988f84f256a3e097e676fe00e352d57ae6aea710624a
BLAKE2b-256 checksum
How to use checksums
2fed5913e6a9f63f8d70e6562e632b163262b4d932cf016664241160da8bbf9c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.15.0 pkginfo/1.7.0 requests/2.22.0 setuptools/50.3.2 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.5.9

Release history Release notifications | RSS feed

This release

2.37.0 This release

1 release file

2.36.0

1 release file

2.35.0

1 release file

2.34.0

1 release file

2.33.0

1 release file

2.32

1 release file

0.0.31

1 release file

0.0.30

1 release file

0.0.29

1 release file

0.0.28

1 release file

0.0.27

1 release file

0.0.25

1 release file

0.0.24

1 release file

0.0.23

1 release file

0.0.18

1 release file

0.0.11

1 release file

0.0.10

1 release file

0.0.9

1 release file

0.0.8

1 release file

0.0.7

1 release file

0.0.5

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page