Code Monkey home page Code Monkey logo

node-rsz's Introduction

rsz Build Status

Resize image files or Buffers

Depends on node-canvas which has special build instructions as it requires Cairo to be installed on your system.

Related

rsz shares the same API as crp, except crp is for cropping images rather than resizing. See also: sz for simply obtaining the size of an image, and thmb for making thumbnails of images.

API

There is one method but multiple ways to use it:

rsz(src, width, height, function (err, buf) { /* */ })

Where src is a String specifying the path to the image or a Buffer containing the image data, and buf is a Buffer containing the resized image data.

rsz(src, width, height, dst, function (err) { /* */ })

Where src is a String specifying the path to the image or a Buffer containing the image data, and dst is a String specifying the path to write the output file to.

rsz(src, { width: w, height: h }, function (err, buf) { /* */ })

Where w and h are the width and height respectively, src is a String specifying the path to the image or a Buffer containing the image data, and buf is a Buffer containing the resized image data.

rsz(src, { width: w, height: h }, dst, function (err) { /* */ })

Where w and h are the width and height respectively, src is a String specifying the path to the image or a Buffer containing the image data, and dst is a String specifying the path to write the output file to.

Options

By default, rsz will return a PNG Buffer or write a PNG file. You can change this when you pass an options object: { height: 100, width: 100, type: 'jpeg' }. You can also adjust the quality with a 'quality' property.

  • 'height' (Number, required) the height of the resized image
  • 'width' (Number, required) the width of the resized image
  • 'type' (String, optional, default: 'png') set to 'jpeg' to return a JPEG Buffer or write a JPEG file.
  • 'quality' (Number, optional) used when creating a JPEG, a number between 1 (lowest quality) and 100 (highest quality).

Example

var rsz = require('rsz')
  , fs  = require('fs')

rsz('/path/to/nyancat.gif', 200, 350, function (err, buf) {
  fs.writeFileSync('/path/to/nyancat_200_350.png', buf)
})

// or

rsz('/path/to/nyancat.gif', 200, 350, '/path/to/nyancat_200_350.png', function (err) {
})

// or

rsz('/path/to/nyancat.gif', { width: 200, height: 350 }, function (err, buf) {
  fs.writeFileSync('/path/to/nyancat_200_350.png', buf)
})

// or

rsz('/path/to/nyancat.gif', { width: 200, height: 350 }, '/path/to/nyancat_200_350.png', function (err) {
})

// or a jpeg

rsz(
    '/path/to/avatar.png'
  , { width: 50, height: 50, type: 'jpeg', quality: 40 }
  , '/path/to/avatar_50_50.jpg'
  , function (err) {
      /* ... */
    }
)

Licence

rsz is Copyright (c) 2013 Rod Vagg @rvagg and licensed under the MIT licence. All rights not explicitly granted in the MIT license are reserved. See the included LICENSE file for more details.

node-rsz's People

Contributors

rvagg avatar

Watchers

Tim Kevin Oxley avatar James Cloos avatar  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.