Electron 1.4.3+ now has a native API for resizing images. You should use those methods instead of this module. This module will stay around but I won't be maintaining it.
Resize images using Electron. Supports all image types that Chromium/Electron supports, outputs to png, jpeg, dataUrl or NativeImage.
$ npm install --save electron-image-resize
const electronImageResize = require('electron-image-resize');
const { writeFileSync } = require('fs');
// Resize the svg image to 40x40
electronImageResize({
url: 'http://electron.atom.io/images/electron-logo.svg',
width: 40,
height: 40
}).then(img => {
// save it as a png file
writeFileSync('/some/path/electron.png', img.toPng());
})
Type: string
Required
URL of image to resize. For local paths prefix the path with 'file://
'.
Type: number
At Least One Is Required
The width in pixels to resize the image to. The height in pixels to resize the image to. If only one dimension is provided, the image will be re-sized so that the original height/width ratio is maintained.
Type: boolean
Default: 500
We will wait until the image is loaded but often you will need to also add a delay to give the renderer time to paint the image before capturing it.
Returns a promise which resolves to a NativeImage. Use methods like .toPng()
and .toJpeg()
to get a buffer which you can use to write to the file system.
MIT © DaveJ