4

I just encountered this question and thought—there has got to be a duplicate target for this: How to get the dimensions of Base64 encoded image in JavaScript.

I did a Google search (get dimensions of dataurl image site:stackoverflow.com) and found a lot of related-looking-ones with similar questions and similar answers. It seems like there's probably opportunity for linking these together for the benefit of future readers, either by non-duplicate links (for example, linking via comments), or duplicate links.

  1. JS - get image width and height from the base64 code
  2. How to find the base64 image width and height
  3. Get height and width dimensions from base64 PNG
  4. Get dimensions from Base64 encoded image
  5. How can i get the Height and Width of image having base64 string source?
  6. how to get width height of an base 64 image

Others that look less similar, but which still look related:

  1. How to get image size (height & width) using JavaScript?
  2. Getting Image Dimensions using Javascript File API

Do any of these make sense to be signposts to other ones? If so, which ones?

I have some knowledge of JavaScript and web APIs, but not enough to feel comfortable initiating anything here.

1
  • Yes, there must be a canonical duplicate somewhere for such a basic question. But the search engine cutoff has seen to questions from 2013 being the youngest in 1. - 6. That's nearly 2,000 days after Stack Overflow launched. It is hard to imagine this wasn't asked in the first hours, days, weeks or months of Stack Overflow's existence. Commented Jan 26, 2023 at 20:31

1 Answer 1

3

Of the bunch... I think the one you found originally that triggered you to go look is actually the least bad.

I pick those words carefully because I still don't really consider the answer "good". The root issue in all of these questions is misunderstanding. Not knowing how images work in a web page, not knowing how to manipulate them in JavaScript, not understanding that images are loaded asynchronously. A lot of these questions for example ask specifically about Base64-encoded images, but that is a red herring. It is no different from an image loaded from a URL.

An answer which does not address any of that and especially does not address the asynchronous nature is essentially a code-only answer in my book. Not good, even if the code works.

2
  • I'm not sure about least bad... It's been using an image of response data from revision 1. So you can't even know that they're talking about a data URL without the image. Though I do agree that there's some missing terminology ("misunderstanding") in these question posts- particularly that they say "base64" instead of "data URL".
    – starball
    Commented Jan 26, 2023 at 20:33
  • @user opinions are such fickle beasts :) Regardless of which one is the least bad, they're all "not good".
    – Gimby
    Commented Jan 27, 2023 at 8:52

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .