Skip to content

Commit

Permalink
create DataView only once
Browse files Browse the repository at this point in the history
  • Loading branch information
silverwind committed Feb 11, 2024
1 parent fab1a27 commit 69a46d0
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions web_src/js/utils/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ export async function pngInfo(blob) {

try {
for (const {name, data} of await pngChunks(blob)) {
const view = new DataView(data.buffer, 0);
if (name === 'IHDR' && data?.length) {
// extract width from mandatory IHDR chunk
const view = new DataView(data.buffer, 0);
width = view.getUint32(0);
} else if (name === 'pHYs' && data?.length) {
// extract dppx from optional pHYs chunk, assuming pixels are square
const view = new DataView(data.buffer, 0);
const unit = view.getUint8(8);
if (unit === 1) {
dppx = Math.round(view.getUint32(0) / 39.3701) / 72; // meter to inch to dppx
Expand Down

0 comments on commit 69a46d0

Please sign in to comment.