Import, rotate, crop and resize pictures into google Cloud Storage
Project description
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.
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
Source code
https://github.com/erwan-lemonnier/cloud-storage-image-resizer
Author
Erwan Lemonnier
github.com/pymacaron
github.com/erwan-lemonnier
www.linkedin.com/in/erwan-lemonnier/
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
Hashes for google-cloud-storage-image-resizer-0.0.10.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 632dd315042c30c62f2466320917348794b86651fd5b88eeb341ab722ee5974c |
|
MD5 | 58e08f64defb6cf3feef5ae498978de9 |
|
BLAKE2b-256 | a86fbaf4626bb04020063dace911f259b8770aed6a73357ee8ab8943aacee423 |