项目作者: sudokai

项目描述 :
libvips image resizing server
高级语言: Go
项目地址: git://github.com/sudokai/imageresizer.git
创建时间: 2018-09-16T21:23:48Z
项目社区:https://github.com/sudokai/imageresizer

开源协议:MIT License

下载


imageresizer

*Warning: at an early stage of development, NOT suitable for production use.*

Prototype of a image resizing server written in Go.

I decided to write this software after dealing with image thumbnailing at
scale (15 million images, multiple thumbnail sizes, 500k new images
per month) at work.

imageresizer attempts to address the image thumbnailing needs of a company
such as the one I work for:

  • High volume of basic resize operations. Fast resizing is a must.
  • Caching of thumbnails and originals, to avoid hitting S3 continuously ($$$).
    Caches should use LRU or LFU with a maximum on-disk size.
  • Ease of deployment and maintenance. No supervisors or http servers.
  • New deployments should incur near-zero downtime.

Getting started

Building and running the code:

Install libvips (minimum required version is v8.5, due to the fact that
we use vips_thumbnail_buffer and libvips‘ new sequential mode).

If you run an older version or another distro: just compile libvips following the official instructions (very easy to do, it takes 60 seconds):

Building libvips from a source tarball

Then:

This project uses Go 1.11’s new go modules, if you don’t have Go 1.11 yet,
run make dep to get the dependencies first.

  1. make
  2. ./imageresizer

URL format:

  1. /{width:[0-9]+}x{height:[0-9]+}/crop/{gravity}/{path}
  2. /{width:[0-9]+}x{height:[0-9]+}/fit/{extend}/{path}

Supported resize operations:

  • crop: resize cropping the edges.
  • fit: resize without cropping (make image smaller if needed).

At the moment, only two gravity settings are supported:

  • s: smart
  • c: center

Supported extend settings (fit then extend edges until target size):

  • 0: do not extend image
  • rrggbb: rgb color in hex format, e.g. ffdea5.

Features

  • Fast resizes using libvips through a cgo bridge (JPEG and PNG)
  • Local caching of originals and thumbnails with approximate LRU eviction based on file atimes.
  • Smart cropping.
  • Image uploads and deletions.
  • S3 storage support.
  • Graceful zero-downtime upgrades/restarts.
  • 304 Not Modified responses.

Examples

Photo Result
Original @samuelclara"">@samuelclara (2400x1600) Original
480x640/crop/s 480x640/crop/s
480x640/crop/c 480x640/crop/c
480x640/fit/0 480x640/fit/0
Original @natcatalyst"">@natcatalyst (3456×5184) Original
300/crop/s 300x300 smart crop
500/fit/000000 500x500 fit

Configuration properties

Put your configuration properties inside a config.properties file in the same directory as the imageresizer executable. The config below contains the default values:

  1. # Listen address
  2. server.addr=:8080
  3. # File storage settings
  4. local.prefix=./images/originals
  5. # S3 settings
  6. s3.enable=false
  7. s3.region={S3 region}
  8. s3.bucket={bucketName}
  9. s3.prefix="" # root path of original images
  10. # Caches
  11. cache.orig.enable=true
  12. cache.orig.path=./images/cache
  13. cache.orig.maxsize=1G
  14. cache.orig.shards=256
  15. cache.thumb.enable=true
  16. cache.thumb.path=./images/thumbnails
  17. cache.thumb.maxsize=1G
  18. cache.thumb.shards=256
  19. cache.loader.sleep=50
  20. cache.loader.files=100
  21. cache.loader.threshold=200
  22. # Uploads
  23. upload.maxsize=50M
  24. # Etag cache size (num items)
  25. etag.cache.enable=true
  26. etag.cache.maxsize=50000

Roadmap

In order of priority:

  • Older libvips (<8.5) compatibility.
  • WEBP and GIF support?
  • Security controls for uploads and deletions?
  • Secure links?
  • Cache sharding.
  • LFU instead of LRU.

Acknowledgements