circle.test.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. import { Jimp, mkJGD, getTestDir } from '@jimp/test-utils';
  2. import configure from '@jimp/custom';
  3. import circle from '../src';
  4. const jimp = configure({ plugins: [circle] }, Jimp);
  5. describe('Circle', () => {
  6. it('makes a circle based on image height and width', async () => {
  7. const expectedImg = await Jimp.read(
  8. getTestDir(__dirname) + '/images/circled.png'
  9. );
  10. const imgSrc = await jimp.read(
  11. mkJGD(
  12. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  13. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  14. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  15. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  16. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  17. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  18. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  19. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  20. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  21. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦'
  22. )
  23. );
  24. imgSrc.circle().bitmap.data.should.be.deepEqual(expectedImg.bitmap.data);
  25. });
  26. it('makes a circle using provided radius', async () => {
  27. const expectedImg = await Jimp.read(
  28. getTestDir(__dirname) + '/images/radius-3-circle.png'
  29. );
  30. const imgSrc = await jimp.read(
  31. mkJGD(
  32. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  33. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  34. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  35. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  36. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  37. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  38. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  39. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  40. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  41. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦'
  42. )
  43. );
  44. imgSrc
  45. .circle({ radius: 3 })
  46. .bitmap.data.should.be.deepEqual(expectedImg.bitmap.data);
  47. });
  48. it('should ', async () => {
  49. const expectedImg = await Jimp.read(
  50. getTestDir(__dirname) + '/images/x-y-circle.png'
  51. );
  52. const imgSrc = await jimp.read(
  53. mkJGD(
  54. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  55. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  56. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  57. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  58. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  59. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  60. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  61. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  62. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦',
  63. '▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦▦'
  64. )
  65. );
  66. imgSrc
  67. .circle({ radius: 5, x: 5, y: 5 })
  68. .bitmap.data.should.be.deepEqual(expectedImg.bitmap.data);
  69. });
  70. });