Skip to content

Commit

Permalink
Use copyResized instead of copy to correctly display avatars of the d…
Browse files Browse the repository at this point in the history
…esired size
  • Loading branch information
gabrieledarrigo committed May 8, 2020
1 parent 9d74499 commit 40b8d01
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ You can follow node-gd installastion's instructions here: [node-gd](https://gith
To install monsterId just type the following command:

```
$ npm install monsterid
$ npm install monsterid
```

## How to use
Expand Down Expand Up @@ -52,13 +52,13 @@ The library is authored in ES6, transpiled with [Babel](https://babeljs.io/), an
To transpile the src files run this command:

```
$ npm run build
$ npm run build
```

To launch all unit tests (with [Jest](https://jestjs.io/)) run this command:

```
$ npm run test
$ npm run test
```

## Credits
Expand Down
2 changes: 1 addition & 1 deletion src/monsterId.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export default async function monsterId(username = '', options = defaultOptions)
const path = `${__dirname}/../images/parts/${part}_${parts[part]}.png`;
// eslint-disable-next-line no-await-in-loop
const image = await gd.createFromPng(path);
image.copy(monster, 0, 0, 0, 0, size, size);
image.copyResized(monster, 0, 0, 0, 0, size, size, 120, 120);

if (part === 'body') {
monster.fill(0, 0, monster.colorAllocate(
Expand Down
10 changes: 5 additions & 5 deletions tests/monsterid.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import monsterId from '../src/monsterId';

const imageMock = {
colorAllocate: jest.fn(),
copy: jest.fn(),
copyResized: jest.fn(),
fill: jest.fn(),
pngPtr: jest.fn(),
};
Expand Down Expand Up @@ -34,8 +34,8 @@ describe('monsterId', () => {
expect(gd.createFromPng, 'Create the image from the monster\'s parts')
.toHaveBeenCalledTimes(6);

expect(imageMock.copy, 'Copy the new image with the choosen monster\'s part')
.toHaveBeenCalledWith(imageMock, 0, 0, 0, 0, 120, 120);
expect(imageMock.copyResized, 'Copy the new image with the choosen monster\'s part')
.toHaveBeenCalledWith(imageMock, 0, 0, 0, 0, 120, 120, 120, 120);

expect(imageMock.fill, 'Fill the avatar\'s background and the monster parts')
.toHaveBeenCalledTimes(2);
Expand All @@ -50,7 +50,7 @@ describe('monsterId', () => {
expect(gd.createTrueColor, 'Create a true color image for the monster with the specified options size')
.toHaveBeenCalledWith(size, size);

expect(imageMock.copy, 'Copy the new image with the choosen monster\'s part with the specified options size')
.toHaveBeenCalledWith(imageMock, 0, 0, 0, 0, size, size);
expect(imageMock.copyResized, 'Copy the new image with the choosen monster\'s part with the specified options size')
.toHaveBeenCalledWith(imageMock, 0, 0, 0, 0, size, size, 120, 120);
});
});

0 comments on commit 40b8d01

Please sign in to comment.