Skip to content

About

Resize images using Electron. Supports all image types that Chromium/Electron supports, outputs to png, jpeg, dataUrl or NativeImage.

Resources

Stars

11 stars

Watchers

5 watching

Forks

Repository files navigation


THIS MODULE IS DEPRECATED

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.


electron-image-resize

Resize images using Electron. Supports all image types that Chromium/Electron supports, outputs to png, jpeg, dataUrl or NativeImage.

Build status: Mac & Linux Build status: Windows

Install

$ npm install --save electron-image-resize

Usage

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());
})

API

electronImageResize(options)

options

url

Type: string
Required

URL of image to resize. For local paths prefix the path with 'file://'.

width and height

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.

delay

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

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.

License

MIT © DaveJ

About

Resize images using Electron. Supports all image types that Chromium/Electron supports, outputs to png, jpeg, dataUrl or NativeImage.

Resources

Stars

11 stars

Watchers

5 watching

Forks

Releases

Packages

Used by

Contributors

Languages