Level 88
You can use onload on the image to get that information
Source: https://exceptionshub.com/js-get-image-width-and-height-from-the-base64-code.html
Hello ,
I would like to get the size of an image loaded using axios :
const arrayBufferToBase64 = (buffer)=> {
let binary = '';
let bytes = [].slice.call(new Uint8Array(buffer));
bytes.forEach((b) => binary += String.fromCharCode(b));
return window.btoa(binary);
};
(...)
const response = await axios.get(
api + '/image/'+params.name,
{headers: headers, responseType: 'arraybuffer'}
).then((res)=>{
let base64Flag = 'data:image;base64,';
let imageStr = arrayBufferToBase64(res);
setPictureContent(base64Flag + imageStr);
setNoPictureAvailable('');
})
;
The image is in the variable pictureContent and I can display it correctly when src={pictureContent}
The question now is : how to get the pictureContent width and height ?
thanks
You can use onload on the image to get that information
Source: https://exceptionshub.com/js-get-image-width-and-height-from-the-base64-code.html
Please or to participate in this conversation.