GithubHelp home page GithubHelp logo

locskeleton / imagmagick2 Goto Github PK

View Code? Open in Web Editor NEW

This project forked from tesserispro/imagmagick2

0.0 1.0 0.0 15 KB

ImageMagick NodeJS module that works. Module is built with MagickWand API.

Python 6.81% C++ 59.94% JavaScript 32.30% C 0.95%

imagmagick2's Introduction

ImageMagic module for NodeJS

Tested with

  • Linux x64
  • Windows x86 / Visual Studio 2015
  • ImageMagic 6.9.6
  • NodeJS 6.7.0

Installation

  1. Install ImageMagic 6.9.6
  2. Windows only configure IMAGEMAGICK_HOME environment variable to root of ImageMagic installation (e.g. C:\Program Files (x86)\ImageMagick-6.9.6-Q16-HDRI )
  3. Windows only If you have problems with ssize_t during build comment line #246 in %IMAGEMAGICK_HOME%\include\magick\magick-baseconfig.h (typedef int ssize_t) TODO: Solve this issue in better way
  4. npm install imagemagic2
  5. electorn only You may need to rebuild library for specific node version user in electron

Usage

Basic Example

To use imagemagick first you need to create and image, currently only reading from file is supported.

const image = require('imagemagick2');

var img = image(filePath);

Than you can apply transformations and/or calculations on image with fluent style. Note than transformations/calculations and even reading image from file will be performed only after apply() method is called.

    const image = require('imagemagick2');
    image(filePath) // Do nothing just save action
        .resize(640, 480) // Do nothing just save action
        .write(destinationPath) // Do nothing just save action
        .apply(); //Apply all actions

Apply returns promise.

    const image = require('imagemagick2');

    image(filePath)
        .resize(640)
        .write(destination)
        .apply()
        .than(() => console.log("OK"))
        .catch(err => console.log("Error: " + err)); 

To handle results of every action you can use action callback. In case of any error action callback will not be called and global promise will fail;

    const image = require('imagemagick2');

    image(filePath)
        .resize(640, 480, function(img){ console.log("Resize finished") })
        .write(destination)
        .apply();

Additionally you can perform any custom action after any operation with method do.

    const image = require('imagemagick2');

    image(filePath)
        .resize(640, 480)
        .do(function(img) { console.log("Resize finished") })
        .write(destination)
        .apply();

Apply time actions

In some cases you may need to decide to continue some transformations or not based on results of previous transformations/calculations. In that case you can use apply time actions.

    const image = require('imagemagick2');

    image(filePath)
        .size(function(img, size) { 
                if(size.width > 640) 
                    img.resize(640)
                       .write(destination); 
              })
        .apply();

Methods

Resize

    const image = require('imagemagick2');
    image(filePath).resize(640, 480, function(img){});

Rotate

    const image = require('imagemagick2');
    image(filePath).rotate(90 /* angle in degrees */, function(img){}); 

Write

    const image = require('imagemagick2');
    image(filePath).write(destinationFilePath, function(img){}); 

Grayscale

    const image = require('imagemagick2');
    image(filePath).grayscale(function(img){}); 

Strip (remove all additional data like EXIF or thumbnails)

    const image = require('imagemagick2');
    image(filePath).strip(function(img){}); 

Size (retrieves image size)

    const image = require('imagemagick2');
    image(filePath).size(function(img, size) { console.log(size.width, size.height) }); 

Brightness histogram

    const image = require('imagemagick2');
    image(filePath).brightnessHistogram(40 /* histogram components number*/, 
            function(img, hist /* array of values, each between 0 and 1 */) { }); 

imagmagick2's People

Contributors

peleshenko 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.