{
  "id": 5280452,
  "title": "Hitting an image size ceiling with Rust and WebAssembly",
  "url": "https://urgent.news/2026/09/03/hitting-an-image-size-ceiling-with-rust-and-webassembly",
  "topic": "tech",
  "section": "Tech",
  "published": "2026-09-03T08:12:16.000Z",
  "source": {
    "name": "Dev.to",
    "slug": "dev-to",
    "url": "https://dev.to/mno_tao_236ab4649edf4cf9f/hitting-an-image-size-ceiling-with-rust-and-webassembly-2e4m"
  },
  "original_language": "en",
  "account": "Hitting an image size ceiling with Rust and WebAssembly involves finding a balance between image quality and file size. Many image tools offer a quality slider, while forms and government portals require the file to be under a certain size, such as 100 KB. These are different problems that need to be addressed separately. The relationship between quality and byte size depends on various factors like pixels, dimensions, color profile, output format, and encoder.\n\nThe goal is to create a HEIC converter that meets a simple invariant: output_bytes = target_kb * 1024. The implementation is performed in the browser using Rust compiled to WebAssembly. The design choices that matter include decoding the HEIC image once and keeping a bounded image object, defining a precise size as a ceiling, and adjusting the search quality for JPEG images based on quality before dimensions.\n\nJPEG encoding is more straightforward since the encoded size is ordered by quality, allowing for binary search within a protected quality interval. If the initial quality doesn't meet the target, the algorithm can skip further probes and resize the image instead. For PNG, the compression level and filter choices do not provide a clean monotonic control over output size, so dimensions are used as the practical lever instead. The conversion path is kept separate from compression, ensuring that the output size is not mistakenly labeled as \"convert\" when shrinking a photo to meet a size constraint.\n\nThe final WebAssembly contract provides metadata about the output, including bytes, MIME type, extension, input and output dimensions, JPEG quality or null for PNG, encoding and resize passes. This keeps the UI code out of the compression algorithm, allowing for a cleaner and more focused implementation. The test suite includes a repository-owned phone photo and checks several targets for both JPEG and PNG, ensuring that the output bytes never exceed the target, JPEG quality never falls below the floor, dimensions are positive and preserve orientation, ICC data survives, and encoding and resize pass counts remain bounded.",
  "summary": "Many image tools expose a quality slider. Forms and government portals usually expose a different requirement: “the file must be under 100 KB.” Those are not the same problem. A quality value is an encoder input. A byte ceiling is a constraint on the output, and the relationship between the two depends on the pixels, dimensions, color profile, output format, and encoder. I wanted a HEIC converter…",
  "key_points": [
    "Implement HEIC converter in browser using Rust compiled to WebAssembly",
    "Outputbytes = targetkb  1024 invariant for image size control",
    "Separate conversion path from compression for clean implementation"
  ],
  "editors_take": null,
  "illustration": null,
  "coverage": {
    "outlets": 2,
    "also_reported_by": [
      {
        "outlet": "Dev.to",
        "title": "Break the Speed Limit: WebAssembly in Next.js & Rust 🦀",
        "url": "https://urgent.news/2026/09/03/break-the-speed-limit-webassembly-in-next-js-rust",
        "published": "2026-09-03T04:09:11.000Z"
      }
    ]
  },
  "ai_generated": true,
  "disclaimer": "Summaries, key points and the editor’s take are written by software from other outlets’ reporting and may contain errors — always check the linked original."
}