Urgent.News

What's breaking now, across thousands of outlets.

Tech

PNG vs JPEG for PDF pages: the chart page agreed, the text page didn't

"Save text as PNG, it's smaller than JPEG" is a rule of thumb for storing PDF pages as images, whether that's lecture slides for revision notes or a paper's figures. On a three-page sample, it held for the chart page only. That page, with flat colours and thin lines, came out at 127,051 bytes as PNG against 178,232 bytes as JPEG at quality 75. The dense small-text page went the other way: 838,404…

When saving PDF pages as images for PDF files, PNG is generally smaller than JPEG, according to a widely held belief. However, this rule is not consistently applicable. For instance, on a three-page sample, it held true only for the chart page. That page, featuring flat colors and thin lines, measured 127,051 bytes as PNG versus 178,232 bytes as JPEG at quality 75.

Conversely, a dense text page was 838,404 bytes in PNG format, approximately 5% larger than JPEG at quality 92 (796,608 bytes). Lossless WebP emerged as the smallest file on both pages for both the text and chart pages.

This sample consisted of a three-page A4 PDF. The first page featured Chinese body text in various sizes (10.5, 9, 7.5, 6, and 5 pt), two small English lines, and a table drawn with 0.3 pt rules. The second page contained vector bar, line, and pie charts, with labels ranging from 6 to 7.5 pt. The third page included a large photograph, a cropped detail, and some 8 pt text.

All elements were created for the test; however, the photograph on the third page was borrowed from a CC0 image by Bonnie Moreland from Wikimedia Commons. Each page underwent processing through poppler at 216 DPI onto a white canvas (1786×2526 pixels), then saved into various formats using Pillow and pngquant. This single pass per setting was completed on an Apple-silicon Mac, ensuring no scans, handwriting, or print-ready files were involved. Consequently, all byte figures presented refer solely to this specific sample.

On the text page, PNG resulted in a file size of 838,404 bytes, while JPEG at quality 75 produced a file size of 535,729 bytes (37.86 dB). At quality 85, JPEG expanded to 647,884 bytes (41.54 dB), and at quality 92, it reached 796,608 bytes (45.92 dB). In contrast, lossless WebP consistently produced smaller files on both text and chart pages, with sizes of 161,212 bytes on the text page and 37,390 bytes on the chart page.

On the text page, lossless WebP was roughly a fifth the size of PNG, and on the chart page, it was under 30% the size. Notably, lossless WebP also came in smaller than the 256-color palette PNG on both pages, which is a lossy format. The photo page exhibited no surprises, with PNG being eight times larger than JPEG at quality 75, and lossless WebP performing worse than every JPEG level.

Both pages had a high percentage of white space (80%). The chart page had a slightly higher percentage of white space (82%) compared to the text page (81%). Additionally, the chart page displayed more distinct colors, approximately 2117 compared to the text page's 447. Thus, neither the increased background nor the fewer colors could determine which page PNG would be smaller.

Instead, the distribution of non-white pixels played a significant role. When dividing each page into 8×8 blocks that JPEG processes, 93.0% of the chart page's blocks were a single flat color, while only 75.5% of the text page's blocks were. Therefore, about a quarter of the text page's blocks contained edges, as opposed to 7.0% on the chart page.

My interpretation is that PNG must precisely preserve every edge pixel, while JPEG at quality 92 is permitted to approximate them. Consequently, pages with more scattered edges benefit more from the lossless format. However, this observation is based solely on these three pages, and I am uncertain about the underlying reason. Additionally, lossless WebP exhibited superior performance with the same edges compared to PNG.

Lastly, the export tool used also affected the results. Using a different browser export tool (ImgIng at imging.ai) with three DPI options (144, 216, 300) led to differing file sizes on the chart page; PNG was larger than JPEG on that page, so the encoder within the tool can vary. For notes, it is recommended to test slides that are predominantly charts, diagrams, and flat colors, as PNG would be the smaller lossless choice and lossless WebP would be even smaller.

For dense text pages, lossless WebP emerged as the clear winner, but only if the destination accepts WebP. If not, JPEG at quality 92 was not larger than PNG on the text page. Lastly, photos should be saved as JPEG. A quick check can be performed by rendering one page of each kind at the desired DPI, saving the same pixels as PNG, JPEG q92, and lossless WebP, and comparing the byte counts.

Finally, zoom in on the smallest text and ensure the letters still appear as intended, regardless of the tool or format chosen.

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

RunsOn vs Blacksmith for GitHub Actions runners

RunsOn vs Blacksmith is a choice between two cost models rather than two rate cards: RunsOn is a flat annual license from 300 euros that installs into your own AWS account and leaves the compute on…

  • RunsOn pricing model costs $29/month for 10,000 Linux minutes
  • Blacksmith charges $0.004 per Linux minute with 3,000 free minutes/month
  • Latchkey offers Linux x64 pricing from $0.0025 to $0.0025 per minute

I mapped a YouTube channel's entire catalog in two runs — for under a cent

Competitor research on YouTube usually dies in one of two places: you click through forty videos by hand and give up, or you start writing a scraper and give up slightly later, somewhere around the…

  • Enumerate channel catalog quickly using first tool with 30-video cap
  • Enrich selected videos with details tool for view counts, durations, likes
  • Two-step approach cost-effective for large channels and other platforms

More from Sunday 15 November →