{"action":"opened","issue":{"url":"https://api.github.com/repos/photopea/UPNG.js/issues/25","repository_url":"https://api.github.com/repos/photopea/UPNG.js","labels_url":"https://api.github.com/repos/photopea/UPNG.js/issues/25/labels{/name}","comments_url":"https://api.github.com/repos/photopea/UPNG.js/issues/25/comments","events_url":"https://api.github.com/repos/photopea/UPNG.js/issues/25/events","html_url":"https://github.com/photopea/UPNG.js/issues/25","id":314066874,"number":25,"title":"RangeError: attempting to construct out-of-bounds TypedArray on ArrayBuffer","user":{"login":"JanisE","id":1469104,"avatar_url":"https://avatars0.githubusercontent.com/u/1469104?v=4","gravatar_id":"","url":"https://api.github.com/users/JanisE","html_url":"https://github.com/JanisE","followers_url":"https://api.github.com/users/JanisE/followers","following_url":"https://api.github.com/users/JanisE/following{/other_user}","gists_url":"https://api.github.com/users/JanisE/gists{/gist_id}","starred_url":"https://api.github.com/users/JanisE/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JanisE/subscriptions","organizations_url":"https://api.github.com/users/JanisE/orgs","repos_url":"https://api.github.com/users/JanisE/repos","events_url":"https://api.github.com/users/JanisE/events{/privacy}","received_events_url":"https://api.github.com/users/JanisE/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-04-13T11:13:36Z","updated_at":"2018-04-13T11:13:36Z","closed_at":null,"author_association":"NONE","body":"Hello! I'm trying to use UPNG.js to optimise the PNG image returned by Canvas, like this:\r\n\r\n```javascript\r\nfunction OpenOptimisedImage(canvas) {\r\n    canvas.toBlob((imageBlob) => {\r\n        const fileReader = new FileReader();\r\n\r\n        fileReader.onloadend = (canvasConvertedToArrayBuffer) => {\r\n            var img  = window.UPNG.decode(\r\n                // 0 = losslessly.\r\n                window.UPNG.encode([canvasConvertedToArrayBuffer.target.result], canvas.width, canvas.height, 0)\r\n            );\r\n            var rgba = window.UPNG.toRGBA8(img)[0];\r\n            var blob = new Blob([rgba], {type:'application/octet-binary'});\r\n\r\n            var reader = new FileReader();\r\n\r\n            reader.onloadend = (optimisedBlobConvertedToBase64) => {\r\n                window.open(optimisedBlobConvertedToBase64.target.result);\r\n            };\r\n            reader.readAsDataURL(blob);\r\n        };\r\n\r\n        fileReader.readAsArrayBuffer(imageBlob);\r\n    });\r\n}\r\n```\r\n\r\nI get an error \"RangeError: attempting to construct out-of-bounds TypedArray on ArrayBuffer\" on line\r\n```\r\nUPNG.encode.compress [..]\r\nvar img32 = new Uint32Array(bufs[j]), ilen = img32.length;\r\n```\r\nif I use the 2.1 version from `npm install` or https://cdnjs.cloudflare.com/ajax/libs/upng-js/2.1.0/UPNG.js, or on line\r\n```\r\nUPNG.encode.framize [..]\r\nvar cimg = new Uint8Array(bufs[j]), cimg32 = new Uint32Array(cimg.buffer);\r\n```\r\nif I'm using the latest `UPNG.js` as it is in the repository now.\r\n\r\nIt seems that `Uint8Array` can be created, but not `Uint32Array`.\r\n\r\nOnly once I got past the first `UPNG.encode` call, and I'm not sure why the error didn't happen then.\r\n\r\nWhat is the problem?"}}
{"actor":{"display_login":"JanisE"}}