fisheye.test.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import { Jimp, mkJGD } from '@jimp/test-utils';
  2. import configure from '@jimp/custom';
  3. import fisheye from '../src';
  4. const jimp = configure({ plugins: [fisheye] }, Jimp);
  5. describe('Fisheye', () => {
  6. it('should create fisheye lens to image', async () => {
  7. const imgNormal = await jimp.read(
  8. mkJGD(
  9. '0000000000',
  10. '0001221000',
  11. '0022222200',
  12. '0122112210',
  13. '0221001220',
  14. '0221001220',
  15. '0122112210',
  16. '0022222200',
  17. '0001221000',
  18. '0000000000'
  19. )
  20. );
  21. const imgBulged = await jimp.read(
  22. mkJGD(
  23. '0001221000',
  24. '0221112220',
  25. '0220000121',
  26. '1100000112',
  27. '2100000012',
  28. '2100000012',
  29. '1200000012',
  30. '0211000222',
  31. '0221111220',
  32. '0012222200'
  33. )
  34. );
  35. imgNormal
  36. .fisheye()
  37. .getJGDSync()
  38. .should.be.sameJGD(imgBulged.getJGDSync());
  39. });
  40. it('should create fisheye lens to image with radius', async () => {
  41. const imgNormal = await jimp.read(
  42. mkJGD(
  43. '0000000000',
  44. '0000000000',
  45. '0000000000',
  46. '0000000000',
  47. '0001111000',
  48. '0001111000',
  49. '0000000000',
  50. '0000000000',
  51. '0000000000',
  52. '0000000000'
  53. )
  54. );
  55. const imgBulged = await jimp.read(
  56. mkJGD(
  57. '■■■■■■■■■■',
  58. '■■■■■■■■■■',
  59. '■■■■■■■■■■',
  60. '■■■11111■■',
  61. '■■111111■■',
  62. '■■111111■■',
  63. '■■■■111■■■',
  64. '■■■■■■■■■■',
  65. '■■■■■■■■■■',
  66. '■■■■■■■■■■'
  67. )
  68. );
  69. imgNormal
  70. .fisheye({ r: 1.8 })
  71. .getJGDSync()
  72. .should.be.sameJGD(imgBulged.getJGDSync());
  73. });
  74. });