src/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,
  20. height = reader.height;
  21. var qu = 100;
  22. var pixels = reader.getData();
  23. var rawImageData = {
  24. data: pixels,
  25. width: width,
  26. height: height
  27. };
  28. var encoder = new JPEGEncoder(qu);
  29. var data = encoder.encode(rawImageData, qu);
  30. return jsPDFAPI.processJPEG.call(this, data, index, alias, compression);
  31. };
  32. })(jsPDF.API);