Giter Site home page Giter Site logo

imconfly / imconfly Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 1.0 131 KB

Web server for full-custom images conversion on-the-fly. Fast cache, low resources consumption.

License: MIT License

JavaScript 100.00%
transform-images image-conversion imagemagick nodejs static-server static-image thumbnails thumbnail-images watermark

imconfly's Introduction

imconfly

NPM version build status App Veyor Test coverage Chat on Gitter

Web server for full-custom images conversion on-the-fly. Fast cache, low resources consumption.

Imconfly uses CLI applications like Imagemagick with full-custom set of parameters for images conversion. This is extremely flexible approach, you can create any transformation you need, using any CLI tool or bunch of CLI tools.

On the other hand, Imconfly is designed for fast serving once transformed images with low resources consumption. These images can be served by Nginx or any fast-and-light static web server.

Quick example

You have an image, https://nodejs.org/static/images/logos/nodejs-1280x1024.png for example. You want to transfom it to 100x100 pixels on red canvas and use on your site permanently.

After configuring and run Imconfly server, your transformed image will be immediately available by URL like this:

http://localhost:9989/nodejs/100x100-red/logos/nodejs-1280x1024.png

Corresponding configuration:

{
  "containers": {
    "nodejs": {
      "root": "https://nodejs.org/static/images",
      "transforms": {
        "100x100-red": "convert \"{source}\" -resize 100x100 -background red -gravity center -extent 100x100 \"{destination}\""
      }
    }
  }
}
  • this example uses convert command from Imagemagick toolkit
  • root settings can be local directory path like /var/www/my_imgs

For example, configuration file is /home/mike/imcf-example/imconfile.json, in this case:

  • Original image will be stored in /home/mike/imcf-example/imconfly_storage/nodejs/origin/logos/nodejs-1280x1024.png
  • Transformed image will be stored in /home/mike/imcf-example/imconfly_storage/nodejs/100x100-red/logos/nodejs-1280x1024.png

This is result of:

  • /home/mike/imcf-example/imconfly_storage - storageRoot setting by default - path to imconfile + "imconfly_storage" +
  • nodejs - container name +
  • 100x100-red - transformation name +
  • logos/nodejs-1280x1024.png - relative path

Command that be called to create the small copy (100x100-red transfomation):

convert "/home/mike/imcf-example/imconfly_storage/nodejs/origin/logos/nodejs-1280x1024.png" -resize 100x100 -background red -gravity center -extent 100x100 "/home/mike/imcf-example/imconfly_storage/nodejs/100x100-red/logos/nodejs-1280x1024.png"

This is an expencive operation, and it performs once, on first-time request. After this, the image will be served as a static file.

Installation

Installation with NPM as global module:

$ npm i -g imconfly

Run:

$ imconfly

Configuration

imconfile

imconfly command needs to configuration file in the current directory or in a some parent directory - imconfile.js or imconfile.json.

For example:

// imconfile.js

module.exports = {
  containers: {
    nodejs: {
      root: "https://nodejs.org/static/images",
      transforms: {
        "100x100-red": "convert \"{source}\" -resize 100x100 -background red -gravity center -extent 100x100 \"{destination}\""
      }
    }
  }
};

imconfile.json:

{
  "containers": {
    "nodejs": {
      "root": "https://nodejs.org/static/images",
      "transforms": {
        "100x100-red": "convert \"{source}\" -resize 100x100 -background red -gravity center -extent 100x100 \"{destination}\""
      }
    }
  }
}

You can copy this to correspond file, run imconfly and check it by this URL:

http://localhost:9989/nodejs/100x100-red/logos/nodejs-1280x1024.png

Relative paths

Relative paths in configuration will be resolved from directory of imconfile.

If your imconfile is /home/mike/imcf-example/imconfile.json, "./imcf_storage" will be resolved as /home/mike/imcf-example/imcf_storage

Global options

  • storageRoot - path to directory with transformed images and origins. Defalut is ./imconfly_storage.
  • port - port to listen by Imconfly application (HTTP protocol). 9989 by default.
  • urlChecker - regexp to check URL format on each request to Imconfly app (/^[\w\./_-]+$/ by default)
  • maxage - amount of seconds for Cache-Control: max-age= http header. Default is 2678400 (31 day).
  • containers - dictonary of containers names. Names must correspond to urlChecker format.

Container options

  • root - http(s) URL with server name and path (http://example.com/my/path) or local filesystem path (/my/path).
  • transforms - dictonary of transforms in name: command format. Command must contains special placeholders - {source} and {destination}.

API

You can use Imconfly inside your apps. For example:

const imconfly = require('imconfly');
const imcfConf = imconfly.conf.Conf.fromFile('imconfile.json');
// or
// const imcfRawConf = require('./imconfile'); 
// const imcfConf = new imconly.conf.Conf(imcfRawConf, __dirname); 
const app = new imconlfy.Imconfly(imcfConf);

app.listen();

Development

Run tests:

$ npm test

Run only specified test suite (server for example):

$ npm test test/server

TODO


Links

License

MIT

imconfly's People

Contributors

gitter-badger avatar i-erokhin avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

gitter-badger

imconfly's Issues

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.