# HTTP Thumbnailer HTTP API server for image thumbnailing and format conversion. It is using [ImageMagick](http://www.imagemagick.org) or [GraphicsMagick](http://www.graphicsmagick.org) via [RMagick](http://rmagick.rubyforge.org) gem as the image processing library. ## Features * thumbnailing images with different aspect ratio keeping methods * identification of image foramt and size * support of many input and output formats * efficient API for generating multiple thumbnails from single input image with just one request * many image scaling and loading performance optimizations * efficient memory usage * memory limits and disk memory offloading support * based on [Unicorn HTTP server](http://unicorn.bogomips.org) with UNIX socket communication support ## Changelog ### 1.1.0 * added identification API for image mime type and size identification * stripping user meta data from input image further reducing output image size * providing image size headers for input image and all generated thumbnails * X-Input-Image-Content-Type header is now deprecated in favour of X-Input-Image-Content-Type * not using [ImageMagick](http://www.imagemagick.org) for input image mime type resolution since it is accessing disk and behaves very inefficiently ## Installing You will need the following system packages installed: `imagemagick`, `pkg-config` and `make`. For PNG support install `libpng`. You may want to consult [ImageMagick](http://www.imagemagick.org) installation guide for more information on supported formats and required libraries. For Arch Linux you can use this commands: ```bash pacman -S imagemagick pacman -S libpng pacman -S pkg-config pacman -S make ``` Then you can install the gem as usual: ```bash gem install httpthumbnailer ``` Optionally install Ruby client library and tool: ```bash gem install httpthumbnailer-client ``` ## Usage ### Getting started ```bash # install httpthumbnailer (see above) # install httpthumbnailer-client gem install httpthumbnailer-client # start thumbnailing server in foreground (to stop hit Ctlr-C) httpthumbnailer --foreground --verbose # in another console thumbnail to standard output cat ~/Pictures/compute.jpg | httpthumbnailer-client -t crop,100,200,png > thumbnail.png # generate multiple thumbnails cat ~/Pictures/compute.jpg | httpthumbnailer-client -t crop,100,200,jpeg,quality:100 -t pad,200,200,png thumbnail1.jpg thumbnail2.png ``` In this example we use [httpthumbnailer-client](http://github.com/jpastuszek/httpthumbnailer-client) gem CLI tool that will use HTTP API of the server to generate thumbnails. ### Running the server HTTP Thumbnailer uses worker based server model thanks to [Unicorn HTTP server](http://unicorn.bogomips.org) gem. To start the thumbnailer use `httpthumbnailer` command. By default it will start in background and will spawn CPU core number + 1 number of worker processes. It will be listening on **localhost** port **3100**. To start in foreground with verbose output use `httpthumbnailer --verbose --foreground`. To see available switches and options use `httpthumbnailer --help`. When running in background the master server process will store it's PID in `httpthumbnailer.pid` file. You can change pid file location with `--pid-file` option. If running as root you can use `--user` option to specify user with whose privileges the worker processes will be running. ### Logging `httpthumbnailer` logs to `httpthumbnailer.log` file in current directory by default. You can change log file location with `--log-file` option and verbosity with `--verbose` or `--debug` switch. Additionally `httpthumbnailer` will log requests in [common NCSA format](http://en.wikipedia.org/wiki/Common_Log_Format) to `httpthumbnailer_access.log` file. Use `--access-log-file` option to change location of access log. ### Supported operations As operation type you can select one of the following options: * fit - fit image within given dimensions keeping aspect ratio * crop - cut image to fit within given dimensions keeping aspect ratio * pad - fit scale image and pad image with background colour to given dimensions keeping aspect ratio * limit - fit scale image to given dimensions if it is larger than that dimensions ### Supported formats List of supported formats can be displayed with `httpthumbnailer --formats`. Optionally format `input` can be used to use the same thumbnail format as input image. ### Thumbnail width and height Width and height values are interpreted depending on operation. `input` string can be used for width and/or height to use input image width or height. ### Thumbnail options Following options can be used with thumbnail specification: * quality - set output image quality; this is format specific: for JPEG 0 is maximum compression and 100 is maximum quality, for PNG first digit is zlib compression level and second one is filter level * background-color - color in HTML notation or textual description ('red', 'green' etc.) used for background when processing transparent images or padding; by default white background is used ### API #### Single thumbnail API To generate single thumbnail send input image with **PUT** request to URI in format: /thumbnail/,,,[,