1.0.2 • Published 8 years ago

skipper-s3-resizer v1.0.2

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago

skipper-s3-resizer

This is extended skipper-s3-resizer based on - Original skipper-s3-resize

New features

Adds optional configurations:

  • prefix - S3 object prefix (Default: '')
  • filename - Custom function for naming files to be uploaded (Default: <uuid>.<ext>).
  • stretch - Whether to stretch or cover image (Default: false).

Changed resizing technique:

  • If width and height are not specified, image will be uploaded in original size
  • If only one dimension is specified, downscale (keeps aspect-ratio)
  • If both dimensions are specified
    • And stretch == true, downscale (breaking aspect-ratio)
    • And stretch == false, downscale (cover)

Based on SailsJS Skipper S3 adapter for receiving upstreams with a twist: Images will be resized before uploading using GraphicMagick.

Installation

  1. Make sure you have graphicmagick installed.
  2. Make sure you have skipper itself installed as your body parser. This is the default configuration in Sails as of v0.10.

  3. Run in your console:

  npm install skipper-s3-resizer --save

Usage

  1. In Controller:
  upload: function(req, res) {
    req.file('image').upload({
      adapter: require('skipper-s3-resizer'), // Required
      key: <YOUR_S3_ACCESS_KEY>, // Required
      secret: <YOUR_S3_SECRET_KEY>, // Required
      bucket: <YOUR_S3_BUCKET>, // Required
      prefix: 'prefixed',
      filename: function (base, ext) {
        return sails.shortid.generate().concat(ext);
      },
      resize: {
        stretch: false,
        width: <WIDTH>,
        height: <HEIGHT>
      },
      headers: { 
        'x-amz-acl': 'public-read'
      }
    }, function(err, uploadedFiles) {
      if(err) return res.serverError(err);
        res.ok();
      });
    }

More info about headers:

References

  1. Original skipper-s3-resize
  2. Skipper documentations.