# archived-node-rsz
**Repository Path**: mirrors_rvagg/archived-node-rsz
## Basic Information
- **Project Name**: archived-node-rsz
- **Description**: An image resizer for Node.js
- **Primary Language**: Unknown
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2020-08-18
- **Last Updated**: 2026-07-18
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# rsz [](http://travis-ci.org/rvagg/node-rsz)
**Resize image files or `Buffer`s**
Depends on [node-canvas](https://github.com/LearnBoost/node-canvas) which has special [build instructions](https://github.com/LearnBoost/node-canvas/wiki/_pages) as it requires **Cairo** to be installed on your system.
## Related
**rsz** shares the same API as **[crp](https://github.com/rvagg/node-crp)**, except **crp** is for *cropping* images rather than resizing. See also: **[sz](https://github.com/rvagg/node-sz)** for simply obtaining the *size* of an image, and **[thmb](https://github.com/rvagg/node-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, dst, width, height, 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, dst, { width: w, height: h }, 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).
* 'aspectRatio' (`Boolean`, optional, default: `false`) set to
`true` to ensure resized image has the same aspect ratio as the original image.
## Examples
```js
var rsz = require('rsz')
, fs = require('fs')
// output resized image as a buffer
rsz('/path/to/nyancat.gif', 200, 350, function (err, buf) {
fs.writeFileSync('/path/to/nyancat_200_350.png', buf)
})
// supply destination file directly
rsz('/path/to/nyancat.gif', 200, 350, '/path/to/nyancat_200_350.png', function (err) {
})
// configure the width and height with an options object
rsz('/path/to/nyancat.gif', { width: 200, height: 350 }, function (err, buf) {
fs.writeFileSync('/path/to/nyancat_200_350.png', buf)
})
// combine options object and output destination
rsz('/path/to/nyancat.gif', { width: 200, height: 350 }, '/path/to/nyancat_200_350.png', function (err) {
})
// maintain aspect ratio
rsz('/path/to/nyancat.gif', { width: 200, height: 200, aspectRatio: true }, function (err, buf) {
})
// resize only one dimension
rsz('/path/to/nyancat.gif', { width: 200 }, function (err, buf) {
})
// resize only one dimension by setting the other dimension to 0
rsz('/path/to/nyancat.gif', 200, 0, function (err, buf) {
})
// rsz also supports convertion between gif, png & 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](https://twitter.com/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.