it('returns a PNG data URL', () => {
const imageA = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', '1x1.png'))
assert.equal(imageA.toDataURL(), 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYlWNgAAIAAAUAAdafFs0AAAAASUVORK5CYII=')
+ assert.equal(imageA.toDataURL({scaleFactor: 2.0}), 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAC0lEQVQYlWNgAAIAAAUAAdafFs0AAAAASUVORK5CYII=')
})
- it('returns a data URL at 1x scale factor', () => {
+ it('returns a data URL at 1x scale factor by default', () => {
const imageA = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
const imageB = nativeImage.createFromBuffer(imageA.toPNG(), {
width: imageA.getSize().width,
})
describe('toPNG()', () => {
- it('returns a buffer at 1x scale factor', () => {
+ it('returns a buffer at 1x scale factor by default', () => {
const imageA = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
const imageB = nativeImage.createFromBuffer(imageA.toPNG(), {
width: imageA.getSize().width,
assert.deepEqual(imageC.getSize(), {width: 538, height: 190})
assert(imageB.toBitmap().equals(imageC.toBitmap()))
})
+
+ it('supports a scale factor', () => {
+ const imageA = nativeImage.createFromPath(path.join(__dirname, 'fixtures', 'assets', 'logo.png'))
+ const imageB = nativeImage.createFromBuffer(imageA.toPNG({scaleFactor: 1.0}))
+ assert.deepEqual(imageB.getSize(), {width: 538, height: 190})
+ const imageC = nativeImage.createFromBuffer(imageA.toPNG({scaleFactor: 2.0}), {scaleFactor: 2.0})
+ assert.deepEqual(imageC.getSize(), {width: 269, height: 95})
+ })
})
describe('createFromPath(path)', () => {