Giter Club home page Giter Club logo

image-thumbs's Introduction

Image Thumbs

Easy-to-use library to create image thumbnails from images existing on some (cloud) object storage or from disk.

Currently implemented is a connection to Google Cloud Storage, but it can be easily extended to other providers.

Supported formats

PNG and JPEG are currently the only supported image formats.

How to use

Sizes

Configure what thumbnails you would like to have in a .yaml file:

thumbs:
  - name: standard      # This name will be added to the thumbnail with an underscore (_)
    # Optional; The default pattern is /{image_stem}_{thumb_name}
    # The original extension is always appended to the end, e.g., `.png`
    naming_pattern: "/{thumb_name}/{image_stem}"
    quality: 80         # PNG ignores this variable as it is always lossless
    size: [ 640, 480 ]  # Target size of the thumbnail. May not always be exact.
    mode: fit           # Available are: 'fit' and 'crop'

  - name: mini
    quality: 80
    size: [ 40, 40 ]
    mode: crop

Google credentials

This crate relies on object_store for the interaction with the storage backend. Currently, this crate only supports Google Cloud Storage.

To configure the Google Service Account, use one of the following environment variables as described in the object_store crate.

GOOGLE_SERVICE_ACCOUNT: location of service account file
GOOGLE_SERVICE_ACCOUNT_PATH: (alias) location of service account file
SERVICE_ACCOUNT: (alias) location of service account file
GOOGLE_SERVICE_ACCOUNT_KEY: JSON serialized service account key
GOOGLE_BUCKET: bucket name
GOOGLE_BUCKET_NAME: (alias) bucket name

Then use it in your code

#[tokio::main]
async fn main() {
    // Path to your thumbnail configuration yaml. You may specify the .yaml extension in the path, but you don't need to.
    let thumbs = image_thumbs::ImageThumbs::new("examples/image_thumbs")
        .await
        .unwrap();
    thumbs
        .create_thumbs("penguin.jpg", "/thumbs", false)  // do not override existing images
        .await
        .unwrap();
    thumbs
        .create_thumbs("penguin.png", "/thumbs", true)  // do override existing images
        .await
        .unwrap();
}

image-thumbs's People

Watchers

abudaan avatar Marlon avatar Erik Jonkers avatar  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.