Giter Site home page Giter Site logo

node-imager's Introduction

Build Status Gittip Dependencies

wip: This is work in progress. Converting to use generators and graphicsmagick-stream library. The uploading is handled by pkgcloud. The master branch and 1.0.0-alpha1 tag works only with s3.

Please use [email protected] which is stable. The 1.0.0-alpha releases are unstable and not recommended for production.

Imager

A node module to resize, crop and upload images (with different variants and presets) to the cloud.

Dependencies

  1. node >= 0.11.12 with --harmony flag
  2. You need to install libgraphicsmagicks.

Using osx

$ brew install graphicsmagick --build-from-source

Using ubuntu

$ sudo apt-get install libgraphicsmagick1-dev

Installation

$ npm install imager

Config

Use a config file. For example imager-config.js

variants

exports.variants = {
  item: {             // variant
    thumb: {          // preset
      options: {      // preset options
        pool: 5,
        scale: { width: 200, height: 150, type: 'contain' },
        crop: { width: 200, height: 150, x: 0, y: 0 },
        format: 'png',
        rotate: 'auto',
      }
    },
    large: {
      original: true  // upload original image without image processing
    }
  },
  gallery: {
    // ...
  }
};

In the above config, item and gallery are variants. thumb and large are presets. Each preset has an options object which is a graphicsmagick-stream config object.

preset options

  • options - An object that is passed to graphicsmagick. See what options are available here

  • rename - A function that accepts an object file as an argument. It has the following properties: name, size, type and path. It is called before uploading each file.

    Example:

    variants.item.thumb.rename = function (file) {
      return 'users/1/thumb/' + file.name;
    };
    var imager = new Imager(variants.item, ...);
  • original - A true value. If this option is set, the original image will be uploaded without any image processing.

storages

exports.storages = {
  local: {
    provider: 'local',
    path: '/tmp',
    mode: 0777
  },
  rackspace: {
    provider: 'rackspace',
    username: process.env.IMAGER_RACKSPACE_USERNAME,
    apiKey: process.env.IMAGER_RACKSPACE_KEY,
    authUrl: 'https://lon.auth.api.rackspacecloud.com',
    region: 'IAD', // https://github.com/pkgcloud/pkgcloud/issues/276
    container: process.env.IMAGER_RACKSPACE_CONTAINER
  },
  amazon: {
    provider: 'amazon',
    key: process.env.IMAGER_S3_KEY,
    keyId: process.env.IMAGER_S3_KEYID,
    container: process.env.IMAGER_S3_BUCKET
  }
}

Usage

var Imager = require('imager');
var config = require('./imager-config.js');
var imager = new Imager(config.variants.item, config.storages.amazon);
// You can also pass only the storage without a variant which will simply
// upload the original image
// new Imager(storages.amazon)

API

.upload(files, callback)

files is an array of files or a single file. A file can be a file object, absolute file path pointing a local file or base64 encoded image data. callback accepts err and an object containing the array of uploaded images.

var config = require('./imager-config.js');
var imager = new Imager(config.variants.item, config.storages.amazon);
imager.upload(files, function (err, avatar) {
  // avatar =>
  // {
  //   thumb: [ 'https://fudge.s3.amazonaws.com/user/1/thumb/image-1.png', ],
  //   large: [ 'https://fudge.s3.amazonaws.com/user/1/large/image-1.png', ]
  // }
});

.remove(files, callback)

files is an array of files or a single file. A file should be the file name of the image on the storage. callback accepts err as an argument.

var config = require('./imager-config.js');
var imager = new Imager(config.storages.amazon);
var files = ['file-1.png']; // or just 'file-1.png'
imager.remove(files, function (err) {

});

.regenerate()

Tests

$ npm test

TODO

  • Support base64 image uploads
  • Implement .remove()
  • Implement .regenerate()
  • Test the api's for rackspace

License

MIT

node-imager's People

Contributors

benighted avatar danielmahon avatar daniloaburto avatar danpe avatar distracteddev avatar frekw avatar jfhbrook avatar madhums avatar nmallinar avatar oblador avatar pwesterdale avatar rubenstolk avatar sascha avatar shauntrennery avatar takeno avatar vikramtiwari avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

node-imager's Issues

add validations

would be nice to have validations for file

{
  size: X,
  type: Y,
  resolution: Z
}

Make resizing actually resize to the given dimensions

By default, using gm to resize will resize to what it deems the best constraint proportionally sized image (unless you pass in "!" as the third argument for resize()). It should still resize the images, but with the size that was passed in. Not sure if this is a node-gm thing in itself, but I spent some time trying to figure it out and it seems the only way to fix it is to force a crop, or use the third param (which won't resize it proportionally).

Performance of upload function

When my program executes to the upload function, it always uploads the first few files, and the entire program gets stuck somewhere. Usually, I have to stop the program, re-run a couple times, before the upload function starts to work again. It seems like theres a peak of the upload function that once my program hops over that peak, the upload function executes perfectly. However, if it doesn't jump over that peak, the program gets stuck. Has this happened to anyone?

does not handle bucket names with periods

issue with using the bucket cdn.example.com, but cdn_example works. I am using imager and S3 which utilizes knox, and first I thought that it was an imager issue but I believe it breaks when imager.js trades off the configuration file to:

var client = knox.createClient(s3Config);

I have also opened an issue with Knox.js

uploads files, then doesn't call callback. runs out of memory after a while.

Its probably an issue on my end to be fair, i installed imagemagick and graphicsmagick. I ported code from your nodejs-express-mongoose demo (which is amazing btw). In the console I get:
mini_1365250326205.png uploaded
detail_1365250326205.png uploaded

but then the console stops, and the imager.upload callback gets never called. I left it running for a couple hours, and osx ran out of memory. The files show up on the S3 bucket fine.

exports.create = function (req, res) {

    var post = new Post( {body:req.files.file.name} ); //req.body)

    post.uploadAndSave(req.files.file, function (err) {

        if (err) {
            res.render('500', {
                title: "500",
                error: err
            })
        }
        else {
            res.json({
                post:post
            }); // '/posts/'+post._id'
        }

    });
}

and

PostSchema.methods = {

    /**
     * Save post and upload image
     *
     * @param {Object} images
     * @param {Function} cb
     * @api public
     */

    uploadAndSave: function (image, cb) {

        var imager = new Imager(imagerConfig, 'S3')
        var self = this

        imager.upload([image], function (err, cdnUri, files) {
            if (err) return cb(err)
            if (files.length) {
                self.image = { cdnUri : cdnUri, files : files }
            }
            console.log( err, cdnUri, files );
            self.save(cb)
        }, 'post')
    }

}

/**

getting filename NaN,NaN. when content-type is application/octet-stream

I'm downloading images from an external website, saving it locally and afterwards uploading it via node-imager to amazon. Sometimes it happens that an image has content-type "application/octet-stream" instead of a supported type. imager doesn't throw an error in this case but uploads the file with filename NaN,NaN,NaN,.. this file is not reachable afterwards.

I' am getting ENOENT Error from imager

{ [Error: ENOENT, stat '/tmp/thumb_1355183462298.png']
 errno: 34,
  code: 'ENOENT',
  path: '/tmp/thumb_1355183462298.png' }

Why I am getting this error while I am uploading images?

storage local

can you help me?
i'm trying a local storage ... but don't worked... is possible?

storage: {
dir: {
path : "/uploadedpath/"
}

Return: { [Error: Command failed: execvp(): No such file or directory
** Have you installed graphicsmagick? **
] code: 127, signal: null }
[ '' ]

the imagemagick is installed!

tks

exif data

does imager remove exif data from images?

Using rotate method of gm package

I'm working on a project in which I'm using your project as a boilerplate. Can you please tell me how can use rotate method of gm properly so that i can not throw any exception because in my case its throwing "execvp() No file or directory found".

Variants should match example config file

I am confused because of the uses of the variant "projects" when the config file has 'items' and 'gallery' as its options. Please think about clarifying this in the documentation.

Generate variants after already uploaded

If we have already successfully uploaded an image to S3 with many variants, how would one be able to create NEW variants for already generated files?

Say for example I added a new template to my site which I want to show a list of content with images resized as 'thumbnail_featured' or something, but already existing files were never uploaded as thumbnail_featured originally. Is there a way to RE-generate variants if passing an existing S3 file?

_NaN on all uploads - Related to changes with Connect

Recent changes to Connect in regards to bodyParser appear to be the cause as everything works fine with node-imager until I update to the latest version of Connect. With that being said, using the newest version of Express is also cause an issue. Any guidance would be greatly appreciated.

folder in the S3 bucket

Hi! now is work my upload with node-imager.

how can I add folders in the S3 bucket according to my variants name?

article: { resize: { .. } ,... },
album: { resize: { .. } ,... },
banner: { resize: { .. } ,... },

myBucket/article/files
myBucket/album/files
myBucket/banner/files

tks

Remove a single Image

Hi,
How can I remove a single image using node-imager. Normally if i provide the name of the image it's removed all the image generated from it.
Now,
If I insert abc.jpg.
I creates several images, like thumb_abc.jpg, preview_abc.jpg.
To remove I have to insert abc.jpg and it removed all the images(thumb_abc.jpg, preview_abc.jpg.)
But I want to remove a single image using it's link ( https://s3.amazonaws.com/themescdn/534a8d27efc5dss-08b0a9ec8be00d85d392c85efcec362dc534e8b2.1920x1080.jpg). Is that possible??

Thanks,
Nixon

s3 uploads are breaking

{ [Error: getaddrinfo ENOTFOUND] code: 'ENOTFOUND', errno: 'ENOTFOUND', syscall: 'getaddrinfo' }
[ '' ]

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: getaddrinfo ENOTFOUND
    at errnoException (dns.js:37:11)
    at Object.onanswer [as oncomplete] (dns.js:124:16)

node 0.10.5 . Related to LearnBoost/knox

Better file type checking

Uploading a image with the extension .jpeg but that is actually a gif makes imagemagic puke.

See enclosed gif.

qkq1k

support local file uploads

Support uploading of local files

// single file upload
imager.upload('apple.png', function (err, files, cdnUri, res){
  // do something
})

also support array of local files

imager.upload(['apple.png', 'orange.png', 'jackfruit.png'], function (err, files, cdnUri, res){
  // do something
})

temp files (.jpg) at root

HI,

Love this package, but, I am seeing what I believe to be temp files created during the image crop/resize process saved in my node project root (the imager tempDir is not set to root).

Any clues?

I have attached one of these files at the bottom of this post.

imager: "version": "0.1.12"
express: "version": "3.4.0"
Ubuntu 13.04 (GNU/Linux 3.8.0-19-generic x86_64)
ImageMagick is version 6.8.7-0

5822-ra5cg9

Error unhandled

I have checked all my code, and everything looks just right. When I try to run the program, I keep getting the same error. I have even set up simple testing program with a static local image, and I'm still getting the error.

throw er; // Unhandled 'error' event

Error: spawn ENOENT
at errnoException (child_process.js:980:11)
at Process.ChildProcess._handle.onexit (child_process.js:771:34)

Do you know what the problem might have been?

EPIPE and failed to upload

when i try to implement imager on nodejitsu, it seem during the upload i always get this error:

POST /menus.json 500 34078ms - 12
{ [Error: write EPIPE] code: 'EPIPE', errno: 'EPIPE', syscall: 'write' }

the imager are configured using S3.

thanks

how to crop to square cut to fit?

When using resizeAndCrop to generate a thumbnail, it would be great if we can cut to fit rather than resizing down, e.g. if the original image is 800 x 600

cropping to a 300x300 should resize the image to 400x300 then cut out 50px on either side to 300 x 300 so that it cuts to fit.

Currently if I do resize:"300x300", crop:"300x300" it will create a 300 x 225 thumbnail instead.

Error: spawn ENOENT

I am using node 0.10.18 with express 3.4.3. I am using a form to submit an image to my local server. The request is coming through in my req.files.img and is being stored on the server. I have validated that the image is being stored and that it has read and write access. I am getting this error in my imager.upload() function before I get any callbacks.

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: spawn ENOENT
    at errnoException (child_process.js:980:11)
    at Process.ChildProcess._handle.onexit (child_process.js:771:34)

Please advise. Thanks!

Mavericks Unhandled 'error' event.

When trying to upload an image to s3 on Mavericks I'm seeing

00:23:45 web.1  | events.js:72
00:23:45 web.1  |         throw er; // Unhandled 'error' event
00:23:45 web.1  |               ^
00:23:45 web.1  | Error: read ECONNRESET
00:23:45 web.1  |     at errnoException (net.js:901:11)
00:23:45 web.1  |     at TCP.onread (net.js:556:19)
00:23:45 web.1  | exited with code 8
00:23:45 system | sending SIGTERM to all processes

I've read the other issues on here with similar errors and the solutions seem to be to either ensure that ImageMagick is installed or to set the region for your S3 configuration.

I've tried both.

Any advice here? Im completely lost. Ive reinstalled ImageMagick with homebrew and my config file includes the region:

region: 'us-standard'

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.