It is possible to create image thumbnails with pure Node.js

3

Well I found a library, which is great for image manipulation, and works perfectly, in this case GraphicsMagick for node.js , but there is a problem because there are dependencies of other softwares installed on the machine where the node will be executed, in this case GraphicsMagick , without it installed it does not scroll, as I believe" the node library is just an interface to the installed software method calls, which may be developed in C or C ++ I think). "

This is my 1st project with node.js, so I do not know very well if it is able to do this and where to start. And whenever I try to search for something like "Create thumbnail picture with node.js" , the results always refer to the libraries quoted above.

  • So I would like to know first, if it is possible to create thumbnails of images only using node.js?
  • "Secondly" , if possible, if there is any library to assist with this task?
  • And "third" , the path of the stones, or any idea how to implement this?
  

Obs¹: My problem with using the cited library ( GraphicsMagick for node.js ) is the need to install a software in hosting, which can be a problem depending on the company's security policy.

     

Note: The only resource I need from this library is resize .

    
asked by anonymous 11.07.2014 / 02:40

1 answer

4

Hello, it is possible to create thumbnails through Node.JS, however, it will require much more advanced knowledge. Currently using external libraries we encounter the following problems:

  • The npm modules require you to pre-install some library as to ImageMagick;
  • Need to start a new external process for each image a be processed.

There is a library called LWIP it works with JPG images, the creator Evil Arubas thought exactly in his idea to minimize the problems with manipulations of images excluding to the maximum the dependency of other libraries, being necessary only a module npm in>.

How to use LWIP:

Perform the installation using the command:

npm install lwip

Create the server.js file:

require('lwip').open('sheldon.jpg', function(err, image){

  // manipulação do evento, caso não consiga abrir a img.
  image.batch()
    .resize(45, 45)  

    .writeFile('output.jpg', function(err){
      // manipulação do evento
    });

});

% LWIP method :

image.resize(width, height, inter, callback)
  • width {Integer} : Width in pixels.
  • height {Integer} : Height in pixels (optional). If not specified, will be calculated by the width ..
  • inter {String} : Interpolation method (optional). By default it is used "lanczos", possible values:
    • "nearest-neighbor"
    • "moving-average"
    • "linear"
    • "grid"
    • "cubic"
    • "lanczos"
  • callback {Function (err, image)}
  • 15.07.2014 / 15:00