forked from jimp-dev/jimp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a93a891
commit 65497b5
Showing
25 changed files
with
419 additions
and
588 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,37 @@ | ||
const fs = require('fs'); | ||
const should = require('should'); | ||
const { Jimp, getTestDir } = require('./test-helper'); | ||
import fs from 'fs'; | ||
import should from 'should'; | ||
import { Jimp, getTestDir } from './test-helper'; | ||
|
||
const imagesDir = getTestDir() + '/samples'; | ||
|
||
describe('Async functions', () => { | ||
it('write returns promise', done => { | ||
const writePath = './test.png'; | ||
|
||
it('write returns promise', async () => { | ||
// process.env is undefined in the browser tests. If BABEL_ENV | ||
// isn't found don't run this test in the browser | ||
if (process.env.ENV === 'browser') { | ||
return done(); | ||
return; | ||
} | ||
|
||
new Jimp(imagesDir + '/dice.png', function(err) { | ||
should.not.exist(err); | ||
const writePath = './test.png'; | ||
const image = await Jimp.read(imagesDir + '/dice.png'); | ||
const writtenImage = await image.writeAsync(writePath); | ||
|
||
this.writeAsync(writePath).then(image => { | ||
should.exist(image); | ||
fs.existsSync(writePath).should.be.true(); | ||
fs.unlinkSync(writePath); | ||
done(); | ||
}); | ||
}); | ||
should.exist(writtenImage); | ||
fs.existsSync(writePath).should.be.true(); | ||
fs.unlinkSync(writePath); | ||
}); | ||
|
||
it('getBuffer returns promise', done => { | ||
if (process.env.ENV === 'browser') { | ||
return done(); | ||
} | ||
it('getBuffer returns promise', async () => { | ||
const image = await Jimp.read(imagesDir + '/dice.png'); | ||
const buffer = await image.getBufferAsync(Jimp.AUTO); | ||
|
||
new Jimp(imagesDir + '/dice.png', function(err) { | ||
should.not.exist(err); | ||
this.getBufferAsync(Jimp.AUTO).then(buffer => { | ||
should.exist(buffer); | ||
done(); | ||
}); | ||
}); | ||
should.exist(buffer); | ||
}); | ||
|
||
it('getBase64 returns promise', done => { | ||
if (process.env.ENV === 'browser') { | ||
return done(); | ||
} | ||
|
||
new Jimp(imagesDir + '/dice.png', function(err) { | ||
should.not.exist(err); | ||
it('getBase64 returns promise', async () => { | ||
const image = await Jimp.read(imagesDir + '/dice.png'); | ||
const bas64 = await image.getBase64Async(Jimp.AUTO); | ||
|
||
this.getBase64Async(Jimp.AUTO).then(buffer => { | ||
should.exist(buffer); | ||
done(); | ||
}); | ||
}); | ||
should.exist(bas64); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,44 @@ | ||
const should = require('should'); | ||
const { Jimp, donutJGD } = require('./test-helper'); | ||
import { Jimp, donutJGD } from './test-helper'; | ||
|
||
describe('canvas color transformation', () => { | ||
const redDonutJGD = donutJGD(0x00000000, 0xff000088, 0xff0000ff); | ||
|
||
it('can apply more than one color transformation', done => { | ||
new Jimp(redDonutJGD, (err, image) => { | ||
should.not.exist(err); | ||
const newJGD = image | ||
.color([ | ||
{ apply: 'hue', params: [-180] }, | ||
{ apply: 'lighten', params: [25] } | ||
]) | ||
.getJGDSync(); | ||
newJGD.should.be.sameJGD(donutJGD(0x40404000, 0x80ffff88, 0x80ffffff)); | ||
done(); | ||
const redDonutJGD = donutJGD(0x00000000, 0xff000088, 0xff0000ff); | ||
|
||
it('can apply more than one color transformation', async () => { | ||
const image = await Jimp.read(redDonutJGD); | ||
const newJGD = image | ||
.color([ | ||
{ apply: 'hue', params: [-180] }, | ||
{ apply: 'lighten', params: [25] } | ||
]) | ||
.getJGDSync(); | ||
|
||
newJGD.should.be.sameJGD(donutJGD(0x40404000, 0x80ffff88, 0x80ffffff)); | ||
}); | ||
}); | ||
|
||
it('lighten', done => { | ||
new Jimp(redDonutJGD, (err, image) => { | ||
should.not.exist(err); | ||
image | ||
.color([{ apply: 'lighten', params: [25] }]) | ||
.getJGDSync() | ||
.should.be.sameJGD(donutJGD(0x40404000, 0xff808088, 0xff8080ff)); | ||
done(); | ||
|
||
it('lighten', async () => { | ||
const image = await Jimp.read(redDonutJGD); | ||
|
||
image | ||
.color([{ apply: 'lighten', params: [25] }]) | ||
.getJGDSync() | ||
.should.be.sameJGD(donutJGD(0x40404000, 0xff808088, 0xff8080ff)); | ||
}); | ||
}); | ||
|
||
it('brighten', done => { | ||
new Jimp(redDonutJGD, (err, image) => { | ||
should.not.exist(err); | ||
image | ||
.color([{ apply: 'brighten', params: [25] }]) | ||
.getJGDSync() | ||
.should.be.sameJGD(donutJGD(0x40404000, 0xff404088, 0xff4040ff)); | ||
done(); | ||
|
||
it('brighten', async () => { | ||
const image = await Jimp.read(redDonutJGD); | ||
|
||
image | ||
.color([{ apply: 'brighten', params: [25] }]) | ||
.getJGDSync() | ||
.should.be.sameJGD(donutJGD(0x40404000, 0xff404088, 0xff4040ff)); | ||
}); | ||
}); | ||
|
||
it('spin hue', done => { | ||
new Jimp(redDonutJGD, (err, image) => { | ||
should.not.exist(err); | ||
image | ||
.color([{ apply: 'hue', params: [150] }]) | ||
.getJGDSync() | ||
.should.be.sameJGD(donutJGD(0x00000000, 0x00ff8088, 0x00ff80ff)); | ||
done(); | ||
|
||
it('spin hue', async () => { | ||
const image = await Jimp.read(redDonutJGD); | ||
|
||
image | ||
.color([{ apply: 'hue', params: [150] }]) | ||
.getJGDSync() | ||
.should.be.sameJGD(donutJGD(0x00000000, 0x00ff8088, 0x00ff80ff)); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.