/**
* @module server/utils/getPngDimensions
*/
const atob = require('atob')
/**
* extract image dimensions (width and height)
* @param base64 {string} base64 encoded png image
* @returns {{width: number, height: number}} image dimensions
*/
module.exports = function getPngDimensions (base64) {
let header = atob(base64.slice(0, 50)).slice(16, 24)
let uint8 = Uint8Array.from(header, c => c.charCodeAt(0))
let dataView = new DataView(uint8.buffer)
const DPI = 150
return {
width: dataView.getInt32(0) / DPI,
height: dataView.getInt32(4) / DPI
}
}