modules/webp_support.js

  1. /**
  2. * @license
  3. * Copyright (c) 2019 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 { JPEGEncoder } from "../libs/JPEGEncoder.js";
  10. import { WebPDecoder } from "../libs/WebPDecoder.js";
  11. /**
  12. * jsPDF webp Support PlugIn
  13. *
  14. * @name webp_support
  15. * @module
  16. */
  17. (function(jsPDFAPI) {
  18. "use strict";
  19. jsPDFAPI.processWEBP = function(imageData, index, alias, compression) {
  20. var reader = new WebPDecoder(imageData, false);
  21. var width = reader.width,
  22. height = reader.height;
  23. var qu = 100;
  24. var pixels = reader.getData();
  25. var rawImageData = {
  26. data: pixels,
  27. width: width,
  28. height: height
  29. };
  30. var encoder = new JPEGEncoder(qu);
  31. var data = encoder.encode(rawImageData, qu);
  32. return jsPDFAPI.processJPEG.call(this, data, index, alias, compression);
  33. };
  34. })(jsPDF.API);