crop.test.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import { Jimp, mkJGD } from '@jimp/test-utils';
  2. import configure from '@jimp/custom';
  3. import crop from '../src';
  4. const jimp = configure({ plugins: [crop] }, Jimp);
  5. describe('crop', () => {
  6. // 6x5 size
  7. const testImage = mkJGD(' ◆◆ ', ' ◆▦▦◆ ', '◆▦▦▦▦◆', ' ◆▦▦◆ ', ' ◆◆ ');
  8. it('full width from top', async () => {
  9. const imgSrc = await jimp.read(testImage);
  10. imgSrc
  11. .crop(0, 0, 6, 2)
  12. .getJGDSync()
  13. .should.be.sameJGD(mkJGD(' ◆◆ ', ' ◆▦▦◆ '));
  14. });
  15. it('full width from bottom', async () => {
  16. const imgSrc = await jimp.read(testImage);
  17. imgSrc
  18. .crop(0, 3, 6, 2)
  19. .getJGDSync()
  20. .should.be.sameJGD(mkJGD(' ◆▦▦◆ ', ' ◆◆ '));
  21. });
  22. it('full width from middle', async () => {
  23. const imgSrc = await jimp.read(testImage);
  24. imgSrc
  25. .crop(0, 2, 6, 2)
  26. .getJGDSync()
  27. .should.be.sameJGD(mkJGD('◆▦▦▦▦◆', ' ◆▦▦◆ '));
  28. });
  29. it('full height from left', async () => {
  30. const imgSrc = await jimp.read(testImage);
  31. imgSrc
  32. .crop(0, 0, 2, 5)
  33. .getJGDSync()
  34. .should.be.sameJGD(mkJGD(' ', ' ◆', '◆▦', ' ◆', ' '));
  35. });
  36. it('full height from right', async () => {
  37. const imgSrc = await jimp.read(testImage);
  38. imgSrc
  39. .crop(4, 0, 2, 5)
  40. .getJGDSync()
  41. .should.be.sameJGD(mkJGD(' ', '◆ ', '▦◆', '◆ ', ' '));
  42. });
  43. it('full height from middle', async () => {
  44. const imgSrc = await jimp.read(testImage);
  45. imgSrc
  46. .crop(2, 0, 2, 5)
  47. .getJGDSync()
  48. .should.be.sameJGD(mkJGD('◆◆', '▦▦', '▦▦', '▦▦', '◆◆'));
  49. });
  50. });