1fbbe18bf65392e0766ab4ea5de24d747a5d8315eb4b5bcf9f080d78e708715ff884cde505604d67b4d23702b91d8641887ef3a9ef090c6819c9d3b8b4c4cb 728 B

1234567891011121314151617181920212223
  1. const getImageSize = require('image-size');
  2. const { svg, xlink } = require('../../namespaces');
  3. /**
  4. * TODO rasterToSVG#getPixelRatioFromFilename
  5. * @param {Buffer} buffer
  6. * @return {string}
  7. */
  8. function rasterToSVG(buffer) {
  9. const info = getImageSize(buffer);
  10. const { width, height, type } = info;
  11. const defaultNS = `${svg.name}="${svg.uri}"`;
  12. const xlinkNS = `${xlink.name}="${xlink.uri}"`;
  13. const data = `data:image/${type};base64,${buffer.toString('base64')}`;
  14. return [
  15. `<svg ${defaultNS} ${xlinkNS} width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">`,
  16. `<image xlink:href="${data}" width="${width}" height="${height}" />`,
  17. '</svg>'
  18. ].join('');
  19. }
  20. module.exports = rasterToSVG;