Giter Site home page Giter Site logo

gcs-serving-url-python's Introduction

Resize your image files on Google Cloud storage with Images Python API powered by Google.

Setup

  1. Clone this repo.
git clone https://github.com/seppe-dalen/gcs-serving-url-python
  1. Install the requirements.
pip install -r requirements.txt -t lib
  1. Deploy to App Engine.
gcloud app deploy

Ensure the targetted bucket and the app engine instance are in the same region

  1. Grant app engine service account permission to the bucket.
  • Find your app engine service account in the IAM & Admin section, copy it
  • Search for cloud storage in GCP
  • Click into a bucket (create a bucket if you don't have any)
  • Go to the permissions tab and add the service account to the permissions with the role Storage Legacy Bucket Owner

Usage

  1. Get a serving url from existed file on Google Cloud Storage:
curl https://PROJECT_NAME.appspot.com/image-url?bucket=mybuckey&image=image_name.jpg
  1. It will return a url that looks something like:
https://lh3.googleusercontent.com/93uhV8K2yHkRuD63KJxlTi7SxjHS8my2emuHmGLZxEmX99_XAjTN3c_2zmKVb3XQ5d8FEkwtgbGjyYpaDQg

Reminders

  1. Only one app can "own" the image. As stated in the documentation for get_serving_url:

If you serve images from Google Cloud Storage, you cannot serve an image from two separate apps. Only the first app that calls get_serving_url on the image can get the URL to serve it because that app has obtained ownership of the image.

  1. The serving url is inherently public (no support for private serving urls) but made in a non guessable way.

Advanced Parameters

SIZE / CROP

  • s640 — generates image 640 pixels on largest dimension
  • s0 — original size image
  • w100 — generates image 100 pixels wide
  • h100 — generates image 100 pixels tall
  • s (without a value) — stretches image to fit dimensions
  • c — crops image to provided dimensions
  • n — same as c, but crops from the center
  • p — smart square crop, attempts cropping to faces
  • pp — alternate smart square crop, does not cut off faces (?)
  • cc — generates a circularly cropped image
  • ci — square crop to smallest of: width, height, or specified =s parameter
  • nu — no-upscaling. Disables resizing an image to larger than its original resolution.

gcs-serving-url-python's People

Contributors

seppe-dalen avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.