Urgent.News

What's breaking now, across thousands of outlets.

Tech

300 DPI means four times the pixels: budget your canvas before rendering a PDF

A JPEG size limit is checked after encoding. A canvas has to exist before that encoding can happen. That ordering matters in a browser PDF-to-image pipeline. Lowering JPEG quality can reduce the downloaded file while leaving the rendering dimensions unchanged. It is useful to give the raster its own budget before asking the browser to allocate it. AI disclosure: this article and its examples were…

The article explains how to budget the pixel dimensions of an image before rendering it as a PDF. It notes that the JPEG size limit is checked after encoding, and lowering JPEG quality can reduce the downloaded file size while keeping rendering dimensions unchanged. The article provides examples showing that doubling the DPI doubles both the width and height dimensions, resulting in four times the pixel count for the same area.

It emphasizes the importance of setting limits on both area and edge length to avoid exceeding browser limits. The provided JavaScript code demonstrates how to calculate the appropriate pixel dimensions based on the requested DPI, maximum edge length, and maximum pixel count. The code includes error handling for invalid inputs and checks if the calculated dimensions fit within the budget.

The article concludes by showing how to validate the results using assertions and emphasizing the need to differentiate between the requested resolution and the actual scale used.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in Tech

Why "Approved" From a Payment Gateway Isn't Enough

If your payment gateway responds with approved: true, do you also check that the approved amount matches what you asked it to charge? We didn't, until this week.

  • Approved transaction amount must match original charge amount
  • PayPhone payment gateway used in Ecuador integration
  • Explicit amount comparison prevents erroneous transactions

More from Thursday 22 October →