Code Monkey home page Code Monkey logo

darkroom's Introduction

Darkroom - Yet Another Image Proxy

build status Coverage Status GoDoc Go Report Card GolangCI GitHub Release Mentioned in Awesome Go

About

Darkroom combines the storage backend and the image processor and acts as an Image Proxy on your image source.
You may implement your own Storage and Processor interfaces to gain custom functionality while still keeping other Darkroom Server functionality.
The native implementations focus on speed and resiliency.

Installation

go get -u github.com/gojek/darkroom

Features

Darkroom acts as an image proxy and currently support several image processing operations such as:

  • Cropping based on given anchor points (top, left, right, bottom)
  • Resizing
  • Grayscaling

Running the Image Proxy Service

The project has docker images available. They can be tested locally or can be be deployed to production.

Create a file containing the environment variables mentioned in config.yaml.example and save it as config.env

Note: Bucket credentials are dummy, you need to provide your own credentials.

DEBUG=true
LOG_LEVEL=debug

APP_NAME=darkroom
APP_VERSION=0.0.1
APP_DESCRIPTION=A realtime image processing service

SOURCE_KIND=s3
SOURCE_BUCKET_NAME=bucket-name
SOURCE_BUCKET_REGION=bucket-region
SOURCE_BUCKET_ACCESSKEY=AKIA*************
SOURCE_BUCKET_SECRETKEY=4y/*******************************
SOURCE_PATHPREFIX=/uploads

PORT=3000

CACHE_TIME=31536000

SOURCE_HYSTRIX_COMMANDNAME=S3_ADAPTER
SOURCE_HYSTRIX_TIMEOUT=5000
SOURCE_HYSTRIX_MAXCONCURRENTREQUESTS=100
SOURCE_HYSTRIX_REQUESTVOLUMETHRESHOLD=10
SOURCE_HYSTRIX_SLEEPWINDOW=10
SOURCE_HYSTRIX_ERRORPERCENTTHRESHOLD=25

Build the docker image and run it with the config created.

make docker-image
docker run -p 80:3000 --env-file ./config.env ${USER}/darkroom:latest

Customisation

You may customise darkroom, for example, you may want to write a storage backend that talks to another service and gets the images. Or might want to create an image processor that uses GPU acceleration to speed up the performance.

Available Interfaces

type Processor interface {
	Crop(img image.Image, width, height int, point CropPoint) image.Image
	Decode(data []byte) (image.Image, string, error)
	Encode(img image.Image, format string) ([]byte, error)
	GrayScale(img image.Image) image.Image
	Resize(img image.Image, width, height int) image.Image
	Watermark(base []byte, overlay []byte, opacity uint8) ([]byte, error)
	Flip(image image.Image, mode string) image.Image
	Rotate(image image.Image, angle float64) image.Image
	FixOrientation(image image.Image, orientation int) image.Image
}
type Storage interface {
	Get(ctx context.Context, path string) IResponse
}
type IResponse interface {
	Data() []byte
	Error() error
	Status() int
}

Any struct implementing the above interfaces can be used with Darkroom.

Note: The struct implementing the Storage interface must return a struct implementing the IResponse interface.

darkroom's People

Contributors

ajatprabha avatar albertusdev avatar baskarap avatar anubhavp28 avatar

Watchers

James Cloos 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.