modules/gif_support.js

  1. /**
  2. * @license
  3. * Copyright (c) 2017 Aras Abbasi
  4. *
  5. * Licensed under the MIT License.
  6. * http://opensource.org/licenses/mit-license
  7. */
  8. import { jsPDF } from "../jspdf.js";
  9. import { GifReader } from "../libs/omggif.js";
  10. import { JPEGEncoder } from "../libs/JPEGEncoder.js";
  11. /**
  12. * jsPDF Gif Support PlugIn
  13. *
  14. * @name gif_support
  15. * @module
  16. */
  17. (function(jsPDFAPI) {
  18. "use strict";
  19. jsPDFAPI.processGIF89A = function(imageData, index, alias, compression) {
  20. var reader = new GifReader(imageData);
  21. var width = reader.width,
  22. height = reader.height;
  23. var qu = 100;
  24. var pixels = [];
  25. reader.decodeAndBlitFrameRGBA(0, pixels);
  26. var rawImageData = {
  27. data: pixels,
  28. width: width,
  29. height: height
  30. };
  31. var encoder = new JPEGEncoder(qu);
  32. var data = encoder.encode(rawImageData, qu);
  33. return jsPDFAPI.processJPEG.call(this, data, index, alias, compression);
  34. };
  35. jsPDFAPI.processGIF87A = jsPDFAPI.processGIF89A;
  36. })(jsPDF.API);