Skip to content

Instantly share code, notes, and snippets.

@balazsorban44
Created March 4, 2022 02:03
Show Gist options
  • Save balazsorban44/363505514dce6696c2075e04358a72a0 to your computer and use it in GitHub Desktop.
Save balazsorban44/363505514dce6696c2075e04358a72a0 to your computer and use it in GitHub Desktop.
Firefox bug: Image natural sizes reported incorrectly after the decode method has finished
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Image width/height after decode</title>
<script>
window.onload = function() {
const img = document.getElementsByTagName('img')[0]
if (img.complete) {
img.src = "http://www.fillmurray.com/100/100"
console.log("before decode", img.naturalHeight, img.naturalWidth)
img.decode().then(() => {
console.log("after decode", img.naturalHeight, img.naturalWidth)
}).catch(e => {
console.log("decode error", e)
})
} else {
console.log("image not loaded")
}
}
</script>
</head>
<body>
<img src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" />
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment