Skip to content

Better image resize, crop, thumbnailing, etc with createImageBitmap() #1390

Open

Description

@sandstrom

Description

Major engines implement createImageBitmap(), but they differ in observable behaviour. I hope this is a good fit for Interop.

These differences affect applications and sites that resize photos before upload, apply EXIF orientation, crop images or sprites, process images in workers, capture video frames, or prepare data for graphics APIs.

The proposed scope covers:

  • Supported ImageBitmapSource types.
  • Cropping, negative dimensions, out-of-bounds pixels, and output dimensions.
  • Resizing and the quality keywords inherit order, e.g. medium < high.
  • imageOrientation: "from-image" and "flipY".
  • colorSpaceConversion and premultiplyAlpha.
  • Invalid input and promise settlement.
  • Origin cleanliness, closing, serialization, and transfer.
  • Window and Worker behaviour covered by WPT.

The scope excludes:

  • Performance.
  • Exact output for "low", "medium", and "high", since HTML does not require particular interpolation algorithms.
  • imageOrientation: "none", which is not in the current HTML enum.

This proposal revisits the Interop 2025 proposal for createImageBitmap, which I also submitted. I've tried to narrow the scope and add details about tests and how they map to browser bugs, which was some of the feedback I got last year.

My think because of quality issues, it's been overlooked by developers. Manipulating images is applicable in many areas. I think usage would be higher if it just worked better and more consistently across browsers.

Hence this proposal!

Evaluator site and examples

I've published a mini-site (and code) for testing differences across browsers, as well as published my findings. The source + code is open, so easy to review.

Site:

https://sandstrom.github.io/create-image-bitmap-comparison/

Code:

https://github.com/sandstrom/create-image-bitmap-comparison/

Findings

These are with my test image, but the code works with any uploaded image.

  • 'pixelated' and 'low' modes yields similar results across browsers
  • With Chrome there is little difference between 'high' and 'medium'.
  • WebKit's 'medium' result is near the reference while 'high' is worse.
  • For edge, 'medium' also seems better than 'high'.

Specification

https://html.spec.whatwg.org/multipage/imagebitmap-and-animations.html#the-imagebitmap-interface

web-feature

createimagebitmap

Test Links

Results

https://wpt.fyi/results/html/canvas/element/manual/imagebitmap?label=master&label=experimental&aligned&q=createimagebitmap

Tests

https://github.com/web-platform-tests/wpt/tree/master/html/canvas/element/manual/imagebitmap

The dashboard contains 20 files and 314 subtests. Experimental runs pass 298
in Chrome, 299 in Edge, 291 in Firefox, and 259 in Safari.

Some related tests cover WebCodecs VideoFrame and wide-gamut canvas sources:

https://wpt.fyi/results/webcodecs?label=master&label=experimental&aligned&q=createImageBitmap

https://wpt.fyi/results/html/canvas/element/manual/wide-gamut-canvas?label=master&label=experimental&aligned&q=ImageBitmap

Someone more knowledgeable than me should decide if the the video source failures and the failure for SVG images without a natural size are relevant and should be in the test selection.

Test gaps

From what I can tell, there are coverage gaps include cropping combined with EXIF orientation, SVG Blob decoding, more Worker source and option combinations, preserving crops through VideoFrame, and stronger colour and alpha checks.

A somewhat elusive thing that's a bit special about this API, is image quality during e.g. resize. If the output isn't "good", developers cannot use it. Sadly, the spec itself doesn't mandate a particular algorithm, but maybe there are still things we can do to improve this area?

I understand that SSIM, SSIMULACRA2, or another perceptual metric may not be on the table.

But for example Chrome has had an issue where 'medium' yielded better results than 'high'. See my test site linked above.

If this isn't considered a great fit for the WPT suite, maybe just doing a shared investigation across the participating browsers against a fixed image corpus, and making sure it's somewhat aligned, i.e. that 'high' or 'medium' doesn't deviate too much across browsers.

Additional Signals

When I asked for feedback on my previous proposal, I was asked for better analysis of WPT coverage and more evidence of developer impact. So I've tried to beef up that section a bit.

Pica, a widely used browser image-resizing library, disables
createImageBitmap() resizing by default. Its documentation says that the
result depends on the browser and recommends its JavaScript and WebAssembly
path for predictable output:

https://github.com/nodeca/pica#new-picaconfig

Chromium issue 41313833 documents poor createImageBitmap() downscaling,
including cases where "medium" produced better results than "high". It has
59 comments and several reproductions:

https://issues.chromium.org/issues/41313833 (merged into https://issues.chromium.org/issues/40044062).

Firefox still has an open bug for the unimplemented resizeQuality option:

https://bugzilla.mozilla.org/show_bug.cgi?id=1363861

Other open reports include:

With better interoperability I think many developers would prefer this API over the more complicated and memory intensive approaches with Canvas or WebAssembly.

Thanks for reading and holding my fingers crossed for this year! 💯

Activity

  1. github-actions commented on Sep 12, 2026

    @github-actions

    This comment was automatically generated based on the information you provided. Please don't edit it.

    Below is additional information about the web feature (from the web-features project) which is referenced in your proposal.
    If this doesn't accurately correspond to your proposal, please update your initial comment to include web-features: <feature-id>.
    To find feature IDs, use the web-features explorer.

    Feature createImageBitmap

    • ID: createimagebitmap
    • Name: createImageBitmap
    • Description: The createImageBitmap() global method creates an ImageBitmap object from a source such as an image, SVG, blob, or canvas. An ImageBitmap object represents pixel data that can be drawn to a canvas with lower latency than other types, such as ImageData.
    • Baseline status: Widely Available
    • Docs: Window: createImageBitmap() method
    • WPT tests: wpt.fyi results
    • More information: See the web-features explorer
  2. jgraham commented on Sep 18, 2026

    @jgraham
    Contributor

    The HTML spec doesn't have any normative requirements for resizeQuality:

    Scale output to the size specified by outputWidth and outputHeight. The user agent should use the value of the resizeQuality option to guide the choice of scaling algorithm.

    Without testable requirements, it's hard to include that in Interop; if you think that web developers need more deterministic algorithms then it might be worth filing an issue on the HTML spec.

    For the browser bugs you mention it would be good to know which, if any, wpt tests they correspond to. The worry is that selecting this area might cause a bunch of edge cases represented in the tests to be fixed, but not actually address the underlying problems you care about.

  3. sandstrom commented on Sep 18, 2026

    @sandstrom
    Author

    @jgraham I agree that the current low/medium/high language is not sufficient for a scored WPT. But that means the quality part needs investigation, not that it is outside interoperability work.

    Seems to be some precedent. For example:

    • JPEG XL in Interop 2026 and progressive rendering, which depends on browser heuristics and had no agreed PASS criterion. Interop accepted it as an Investigation Effort.
    • Editing and contenteditable had behavior that existing specifications and tests did not describe well enough. Browsers collaborated first to define the intended goals and testing strategy.
    • Web Audio sometimes separates observable constraints from implementation freedom, for example compressor curves may be chosen by the UA, but must be continuous and monotonic.
  4. jgraham commented on Sep 18, 2026

    @jgraham
    Contributor

    Yes, you can definitely split this proposal into a focus area part and an investigation part; if you want to do that please file a separate issue for the latter.

    When assessing proposals clarity on the intended scope is really helpful because it means that people are on the same page about what the proposal actually requires. For focus area proposals that ultimately means what's covered by the tests, and mismatches between what the proposal hopes to cover and what the tests actually cover can be a negative signal because it suggests that even if you select the proposal you might not actually solve the underlying problem.

  5. sandstrom commented on Sep 18, 2026

    @sandstrom
    Author

    @jgraham Alright, I see your point, and thanks for engaging! 😄

    But if we stay on the 'focus area part' a bit longer.

    I'm no web spec wizard, but if you ask me, even a spec that doesn't mandate an algorithm, when you have different quality levels named 'low', 'medium' and 'high', the only reasonable interpretation should be that 'high' should yield higher-quality results than 'medium', right? (honest question, let me know if you disagree)

    Because right now, 2 out of 4 browsers tested will yield better results in medium than on high.

    I can see why it might happen. For example, I think an implementation on 'medium' might grab a mathematically averaged, smaller version from its internal mipmap tree, smoothing out the harsh transitions and producing a cleaner/sharper downscaled result.

    But this isn't about how it happens, my objection is that it's hard for developers to use across browsers, because you need to know details if each browser implementation to know whether you should pick 'medium' or 'high' for the best result. Also might vary between upscale and downscale.

    To me, this feels like an interop problem and a testable requirement, even when leaving the fact that algo is not specified in spec. The 'order' of the quality enum does signal something meaningful, which isn't true.

    I've published a mini-site (with source code) where you can upload any image and see results for each quality factor (or compare browsers).

    If you want to quickly batch say 10 images across all browsers and compare, ask your agent to use e.g. Playwright CLI to do it quickly.

    Site:
    https://sandstrom.github.io/create-image-bitmap-comparison/

    Code:
    https://github.com/sandstrom/create-image-bitmap-comparison/

  6. jgraham commented on Sep 24, 2026

    @jgraham
    Contributor

    I agree that seems natural, but I can also imagine lots of reasons that it might not work out in practice (e.g. for specific inputs your fast "medium" algorithm might give better output than your slower "high" algorithm).

    So I agree that you could reasonably file browser bugs and complain about the current behaviour if it doesn't match expectations. And I agree it's annoying! It's just hard to include in Interop until there's actual spec text to document agreement about what the required constraints are, and web-platform-tests that check those requirements.

  7. ccameron-chromium commented on Sep 29, 2026

    @ccameron-chromium

    I would like to get the spec into a better place here. In particular:

    • colorSpaceConversion: default
      • default should not be implementation-defined
        • it should should retain the color space information
        • color space conversion should be applied in the ultimate consumer (ImageBitmapRenderingContext, drawImage, texImage2D, etc).
      • none
        • should mean "reinterpret the RGB pixel values as srgb". It should also clarify that for formats that are YUV (almost all), the YUV to RGB conversion must be done
    • premultiplyAlpha
      • this should have no effect -- it's an anti-optimization

    I would like to see this cleaned up, but it needs to be cleaned up in the spec first.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    focus-area-proposal

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions