jpeg.test.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { Jimp, getTestDir } from '@jimp/test-utils';
  2. import configure from '@jimp/custom';
  3. import jpeg from '../src';
  4. const jimp = configure({ types: [jpeg] }, Jimp);
  5. describe('JPEG', () => {
  6. const imagesDir = getTestDir(__dirname) + '/images';
  7. it('load JPG', async () => {
  8. const image = await jimp.read(imagesDir + '/cops.jpg');
  9. image.getPixelColor(10, 10).should.be.equal(0x3f4a02ff);
  10. image.getPixelColor(220, 190).should.be.equal(0x5d94b6ff);
  11. image.getPixelColor(350, 130).should.be.equal(0xdf7944ff);
  12. });
  13. it('load JPG with fill bytes', async () => {
  14. const image = await jimp.read(imagesDir + '/fillbytes.jpg');
  15. image.getPixelColor(10, 10).should.be.equal(0xaeb8c3ff);
  16. image.getPixelColor(220, 190).should.be.equal(0x262b21ff);
  17. image.getPixelColor(350, 130).should.be.equal(0x4e5d30ff);
  18. });
  19. it('export JPG', async () => {
  20. const image = await jimp.read({
  21. width: 3,
  22. height: 3,
  23. data: [
  24. 0xff0000ff,
  25. 0xff0080ff,
  26. 0xff00ffff,
  27. 0xff0080ff,
  28. 0xff00ffff,
  29. 0x8000ffff,
  30. 0xff00ffff,
  31. 0x8000ffff,
  32. 0x0000ffff
  33. ]
  34. });
  35. image.quality(50);
  36. const buffer = await image.getBufferAsync('image/jpeg');
  37. buffer.toString().should.match(/^.{3,9}JFIF\u0000/);
  38. });
  39. });