New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

imagemagick-native

Package Overview
Dependencies
Maintainers
2
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

imagemagick-native - npm Package Compare versions

Comparing version 1.5.0 to 1.6.0

test/test.gravity.js

2

package.json

@@ -10,3 +10,3 @@ {

],
"version": "1.5.0",
"version": "1.6.0",
"license": "MIT",

@@ -13,0 +13,0 @@ "repository": {

# node-imagemagick-native
[Imagemagick](http://www.imagemagick.org/)'s [Magick++](http://www.imagemagick.org/Magick++/) binding for [Node](http://nodejs.org/).
[ImageMagick](http://www.imagemagick.org/)'s [Magick++](http://www.imagemagick.org/Magick++/) binding for [Node](http://nodejs.org/).

@@ -15,2 +15,7 @@ Features

* [Examples](#examples)
* [Convert formats](#example-convert) (PNG to JPEG)
* [Blur](#example-blur)
* [Resize](#example-resize)
* [Rotate, flip, and mirror](#example-rotate-flip-mirror)
* [API Reference](#api)

@@ -24,11 +29,116 @@ * [`convert`](#convert)

* [`version`](#version)
* [Examples](#examples)
* [Convert formats](#example-convert) (PNG to JPEG)
* [Blur](#example-blur)
* [Resize](#example-resize)
* [Rotate, flip, and mirror](#example-rotate-flip-mirror)
* [Installation](#installation)
* [Linux / Mac OS X](#installation-unix)
* [Windows](#installation-windows)
* [Performance](#performance)
* [License](#license)
<a name='examples'></a>
## Examples
<a name='example-convert'></a>
### Convert formats
Convert from one format to another with quality control:
```js
fs.writeFileSync('after.png', imagemagick.convert({
srcData: fs.readFileSync('before.jpg'),
format: 'PNG',
quality: 100 // (best) to 1 (worst)
}));
```
Original JPEG:
![alt text](http://elad.github.io/node-imagemagick-native/examples/quality.jpg 'Original')
Converted to PNG:
quality 100 | quality 50 | quality 1
:---: | :---: | :---:
![alt text](http://elad.github.io/node-imagemagick-native/examples/quality_100.png 'quality 100') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/quality_50.png 'quality 50') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/quality_1.png 'quality 1')
*Image courtesy of [David Yu](https://www.flickr.com/photos/davidyuweb/14175248591).*
<a name='example-blur'></a>
### Blur
Blur image:
```js
fs.writeFileSync('after.jpg', imagemagick.convert({
srcData: fs.readFileSync('before.jpg'),
blur: 5
}));
```
![alt text](http://elad.github.io/node-imagemagick-native/examples/blur_before.jpg 'Before blur') becomes ![alt text](http://elad.github.io/node-imagemagick-native/examples/blur_after.jpg 'After blue')
*Image courtesy of [Tambako The Jaguar](https://www.flickr.com/photos/tambako/3574360498).*
<a name='example-resize'></a>
### Resize
Resized images by specifying `width` and `height`. There are three resizing styles:
* `aspectfill`: Default. The resulting image will be exactly the specified size, and may be cropped.
* `aspectfit`: Scales the image so that it will not have to be cropped.
* `fill`: Squishes or stretches the image so that it fills exactly the specified size.
```js
fs.writeFileSync('after_resize.jpg', imagemagick.convert({
srcData: fs.readFileSync('before_resize.jpg'),
width: 100,
height: 100,
resizeStyle: 'aspectfill', // is the default, or 'aspectfit' or 'fill'
gravity: 'Center' // optional: position crop area when using 'aspectfill'
}));
```
Original:
![alt text](http://elad.github.io/node-imagemagick-native/examples/resize.jpg 'Original')
Resized:
aspectfill | aspectfit | fill
:---: | :---: | :---:
![alt text](http://elad.github.io/node-imagemagick-native/examples/resize_aspectfill.jpg 'aspectfill') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/resize_aspectfit.jpg 'aspectfit') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/resize_fill.jpg 'fill')
*Image courtesy of [Christoph](https://www.flickr.com/photos/scheinwelten/381994831).*
<a name='example-rotate-flip-mirror'></a>
### Rotate, flip, and mirror
Rotate and flip images, and combine the two to mirror:
```js
fs.writeFileSync('after_rotateflip.jpg', imagemagick.convert({
srcData: fs.readFileSync('before_rotateflip.jpg'),
rotate: 180,
flip: true
}));
```
Original:
![alt text](http://elad.github.io/node-imagemagick-native/examples/rotateflip.jpg 'Original')
Modified:
rotate 90 degrees | rotate 180 degrees | flip | flip + rotate 180 degrees = mirror
:---: | :---: | :---: | :---:
![alt text](http://elad.github.io/node-imagemagick-native/examples/rotateflip_rotate_90.jpg 'rotate 90') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/rotateflip_rotate_180.jpg 'rotate 180') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/rotateflip_flip.jpg 'flip') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/rotateflip_mirror.jpg 'flip + rotate 180 = mirror')
*Image courtesy of [Bill Gracey](https://www.flickr.com/photos/9422878@N08/6482704235).*
<a name='api'></a>
## API
## API Reference

@@ -51,6 +161,8 @@ <a name='convert'></a>

resizeStyle: optional. default: 'aspectfill'. can be 'aspectfit', 'fill'
aspectfill: keep aspect ratio, get the exact provided size,
crop top/bottom or left/right if necessary
aspectfill: keep aspect ratio, get the exact provided size.
aspectfit: keep aspect ratio, get maximum image that fits inside provided size
fill: forget aspect ratio, get the exact provided size
gravity: optional. default: 'Center'. used to position the crop area when resizeStyle is 'aspectfill'
can be 'NorthWest', 'North', 'NorthEast', 'West',
'Center', 'East', 'SouthWest', 'South', 'SouthEast', 'None'
format: optional. output format, ex: 'JPEG'. see below for candidates

@@ -248,114 +360,13 @@ filter: optional. resize filter. ex: 'Lagrange', 'Lanczos'. see below for candidates

<a name='installation'></a>
<a name='examples'></a>
## Installation
## Examples
<a name='installation-unix'></a>
<a name='example-convert'></a>
### Linux / Mac OS X
### Convert formats
Install [ImageMagick](http://www.imagemagick.org/) with headers before installing this module.
Tested with ImageMagick 6.7.7 on CentOS 6 and Mac OS X Lion, Ubuntu 12.04 .
Convert from one format to another with quality control:
```js
fs.writeFileSync('after.png', imagemagick.convert({
srcData: fs.readFileSync('before.jpg'),
quality: 100 // (best) to 1 (worst)
}));
```
Original JPEG:
![alt text](http://elad.github.io/node-imagemagick-native/examples/quality.jpg 'Original')
Converted to PNG:
quality 100 | quality 50 | quality 1
:---: | :---: | :---:
![alt text](http://elad.github.io/node-imagemagick-native/examples/quality_100.png 'quality 100') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/quality_50.png 'quality 50') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/quality_1.png 'quality 1')
*Image courtesy of [David Yu](https://www.flickr.com/photos/davidyuweb/14175248591).*
<a name='example-blur'></a>
### Blur
Blur image:
```js
fs.writeFileSync('after.jpg', imagemagick.convert({
srcData: fs.readFileSync('before.jpg'),
blur: 5
}));
```
![alt text](http://elad.github.io/node-imagemagick-native/examples/blur_before.jpg 'Before blur') becomes ![alt text](http://elad.github.io/node-imagemagick-native/examples/blur_after.jpg 'After blue')
*Image courtesy of [Tambako The Jaguar](https://www.flickr.com/photos/tambako/3574360498).*
<a name='example-resize'></a>
### Resize
Resized images by specifying `width` and `height`. There are three resizing styles:
* `aspectfill`: Default. The resulting image will be exactly the specified size, and may be cropped.
* `aspectfit`: Scales the image so that it will not have to be cropped.
* `fill`: Squishes or stretches the image so that it fills exactly the specified size.
```js
fs.writeFileSync('after_resize.jpg', imagemagick.convert({
srcData: fs.readFileSync('before_resize.jpg'),
width: 100,
height: 100,
resizeStyle: 'aspectfill' // is the default, or 'aspectfit' or 'fill'
}));
```
Original:
![alt text](http://elad.github.io/node-imagemagick-native/examples/resize.jpg 'Original')
Resized:
aspectfill | aspectfit | fill
:---: | :---: | :---:
![alt text](http://elad.github.io/node-imagemagick-native/examples/resize_aspectfill.jpg 'aspectfill') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/resize_aspectfit.jpg 'aspectfit') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/resize_fill.jpg 'fill')
*Image courtesy of [Christoph](https://www.flickr.com/photos/scheinwelten/381994831).*
<a name='example-rotate-flip-mirror'></a>
### Rotate, flip, and mirror
Rotate and flip images, and combine the two to mirror:
```js
fs.writeFileSync('after_rotateflip.jpg', imagemagick.convert({
srcData: fs.readFileSync('before_rotateflip.jpg'),
rotate: 180,
flip: true
}));
```
Original:
![alt text](http://elad.github.io/node-imagemagick-native/examples/rotateflip.jpg 'Original')
Modified:
rotate 90 degrees | rotate 180 degrees | flip | flip + rotate 180 degrees = mirror
:---: | :---: | :---: | :---:
![alt text](http://elad.github.io/node-imagemagick-native/examples/rotateflip_rotate_90.jpg 'rotate 90') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/rotateflip_rotate_180.jpg 'rotate 180') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/rotateflip_flip.jpg 'flip') | ![alt text](http://elad.github.io/node-imagemagick-native/examples/rotateflip_mirror.jpg 'flip + rotate 180 = mirror')
*Image courtesy of [Bill Gracey](https://www.flickr.com/photos/9422878@N08/6482704235).*
## Installation
### Linux / Mac
Install [Imagemagick](http://www.imagemagick.org/) with headers before installing this module.
Tested with ImageMagick 6.7.7 on CentOS6 and MacOS10.7, Ubuntu12.04 .
brew install imagemagick

@@ -392,2 +403,4 @@

<a name='installation-windows'></a>
### Windows

@@ -411,2 +424,4 @@

<a name='performance'></a>
## Performance - simple thumbnail creation

@@ -421,2 +436,3 @@

<a name='license'></a>

@@ -423,0 +439,0 @@ ## License (MIT)

@@ -16,2 +16,20 @@ var test = require('tap').test

test( 'convert invalid format', function (t) {
var buffer;
try {
buffer = imagemagick.convert({
srcData: require('fs').readFileSync( "test.png" ), // 58x66
width: 100,
height: 100,
quality: 80,
format: 'PNGX',
debug: debug
});
} catch (e) {
t.like( e.message, /no decode delegate for this image format/, 'err message' );
}
t.equal( buffer, undefined, 'buffer undefined' );
t.end();
});
test( 'convert invalid number of arguments', function (t) {

@@ -18,0 +36,0 @@ var error = 0;

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc