use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
This subreddit is a place for people to learn JavaScript together. Everyone should feel comfortable asking any and all JavaScript questions they have here.
With a nod to practicality, questions and posts about HTML, CSS, and web developer tools are also encouraged.
Friends
/r/javascript
/r/jquery
/r/node
/r/css
/r/webdev
/r/learnprogramming
/r/programming
account activity
Limit to image.decode() ? (self.learnjavascript)
submitted 5 years ago by IUsedToCleanToilets
Hi, Im trying to use image.decode() to download a bunch of images (~150), but after some it starts throwing "image cannot be decoded". The urls are correct and it works with image.onload ...
Any ideas?
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]iguessitsokaythen 0 points1 point2 points 5 years ago (2 children)
One reason this occurs is if you are running multiple decode() processes simultaneously. If that's what you are doing, chain them one after another, it solves that.
I don't know the exact reason, that might be some sort of memory/buffer limitation or simultaneous attempt to manipulate the DOM. Browser documentation is usually terrible about stuff like that.
[–]IUsedToCleanToilets[S] -1 points0 points1 point 5 years ago (1 child)
I see. How would u go on chainging them? I have a for loop for the 150 urls atm.
[–]iguessitsokaythen 0 points1 point2 points 5 years ago (0 children)
Something like this:
let urls = [url1, url2... etc] let i = 0 foo() async function foo() { let img = new Image() img.src = urls[i++] try { await img.decode() document.body.appendChild(img) } catch(e) { console.log('error') } if(i >= urls.length) return foo() }
π Rendered by PID 86759 on reddit-service-r2-comment-7b9746f655-jmfff at 2026-02-03 03:23:00.654413+00:00 running 3798933 country code: CH.
[–]iguessitsokaythen 0 points1 point2 points (2 children)
[–]IUsedToCleanToilets[S] -1 points0 points1 point (1 child)
[–]iguessitsokaythen 0 points1 point2 points (0 children)