modules/webp_support.js

  1. /* global jsPDF, JPEGEncoder, WebPDecoder */
  2. /**
  3. * @license
  4. * Copyright (c) 2019 Aras Abbasi
  5. *
  6. * Licensed under the MIT License.
  7. * http://opensource.org/licenses/mit-license
  8. */
  9. /**
  10. * jsPDF webp Support PlugIn
  11. *
  12. * @name webp_support
  13. * @module
  14. */
  15. (function (jsPDFAPI) {
  16. 'use strict';
  17. jsPDFAPI.processWEBP = function (imageData, index, alias, compression) {
  18. var reader = new WebPDecoder(imageData, false);
  19. var width = reader.width, height = reader.height;
  20. var qu = 100;
  21. var pixels = reader.getData();
  22. var rawImageData = {
  23. data: pixels,
  24. width: width,
  25. height: height
  26. };
  27. var encoder = new JPEGEncoder(qu);
  28. var data = encoder.encode(rawImageData, qu);
  29. return jsPDFAPI.processJPEG.call(this, data, index, alias, compression);
  30. };
  31. })(jsPDF.API);