Modern Image Formats at Discord: Supporting WebP and AVIF
In the past six months, Discord’s Media Infrastructure team has modernized our image pipeline by adding support for animated WebP and AVIF formats. You can now share animated WebP and AVIF content through attachments and embeds, while all animated emojis are served as animated WebP — displaying seamlessly on every Discord platform. These changes are designed to enable higher quality animations and better playback performance across all platforms while drastically decreasing file sizes, and in turn, making them load faster!
The Evolution of Image FormatsJust as the transition from standard-definition to high-definition video transformed visual media, modern image formats are revolutionizing how we share visual content online. At Discord, where millions of users share billions of images daily, we’re constantly evaluating how to deliver the best possible visual experience while maintaining performance and efficiency.
The venerable GIF format has served the internet well for decades, becoming synonymous with short, looping animations powering memes everywhere (and years of debate on how it’s pronounced). However, GIF’s limitations — including a 256-color palette, lack of true alpha transparency, and inefficient compression — have become increasingly apparent as displays and network capabilities have evolved.
Modern formats like WebP and AVIF represent a quantum leap forward in image technology, offering capabilities that align better with Discord’s needs:
True Alpha TransparencyUnlike GIF’s binary transparency, where pixels are either fully visible or invisible, WebP and AVIF support variable transparency levels (or alpha channels). This enables smooth edges and partial transparency effects that are essential for high-quality animated stickers and emotes. For Discord’s dark and light themes, this means animations can blend seamlessly with any background.
The image below uses a diagonal blue-to-red gradient background to demonstrate how different image formats handle transparency. The left side shows smooth alpha transitions, while the right side shows binary (on/off) transparency. The comparison reveals that while WebP and AVIF can handle smooth transparency gradients perfectly, though all formats handle simple binary transparency equally well.
Enhanced Color Depth
While GIF is limited to 8 bits per pixel for a total of 256 colors, WebP provides 8 bits per color channel equating to a staggering 16 million colors, and AVIF pushes even further with up to 12 bits per channel. This dramatic increase in color fidelity means:
- Smoother gradients without visible banding
- More vibrant and accurate colors
- Better representation of photographic content
- Support for HDR content on compatible displays
Both WebP and AVIF utilize modern video compression techniques for animations, leading to dramatically smaller file sizes compared to GIF:
- Inter-frame compression that only encodes pixel changes between frames
- Advanced prediction modes that reduce redundant data
- Configurable quality levels to balance size and visual fidelity
- Support for variable frame timing with millisecond precision
The growing adoption of WebP and AVIF, particularly on mobile devices where every kilobyte counts, allows more users to experience these benefits. However, implementing support for these formats presents unique technical challenges, from efficient decoding to graceful fallbacks for unsupported platforms. In the following sections, we’ll dive into how Discord tackled these challenges to bring next-generation image support to our users.
The Technical ChallengeModernizing Discord’s image pipeline wasn’t just about adding new format support — it required careful orchestration across our entire media infrastructure. With hundreds of millions of daily active users sharing billions of images, we needed to maintain seamless compatibility while enabling a smooth transition to these modern formats.
Cross-Platform ComplexitySupporting new image formats at Discord’s scale means ensuring they work reliably everywhere. Our app spans across web browsers, desktop (Windows, macOS, Linux), iOS, and Android, each with their own unique requirements and constraints. Discord must inspect, convert, and resize every still and animated image attached, and embed properly to ensure a consistent viewing experience for all users across our many platforms. This is at the heart of why introducing support for new formats is so challenging.
While both WebP and AVIF offer compelling advantages, we needed clear criteria for choosing between the two to support. WebP became our preferred transformation target for several reasons:
- Near universal support across platforms
- Faster encode/decode times compared to AVIF
- Mature tooling and widespread ecosystem support
- Predictable performance characteristics
However, this choice involves some tradeoffs:
- Limited to 8-bit color depth compared to AVIF’s 10/12-bit support, particularly important for HDR content that typically uses 10-bit color
- Larger file sizes than equivalent AVIF files
- Less efficient compression for certain content types
To ensure maximum compatibility, we convert AVIF content to WebP while maintaining the highest possible visual quality. HDR AVIF sources are tone-mapped to SDR to preserve as much of the original color characteristics as possible.
iOS PerformanceDisplaying animated WebP content on iOS proved to be an irksome challenge. Discord uses the SDWebImage library to efficiently render images of all kinds on iOS. SDWebImage has a built-in mechanism for rendering WebP images with Apple’s ImageIO framework, which seemed like the obvious solution since it leveraged capabilities built into iOS 14+.
However, performance testing uncovered a problem with frame timing consistency: animated WebP files would play progressively slower over time. The issue was especially noticeable with animations that had higher resolutions or more frames.
The following video shows a side-by-side comparison of animated WebP decoding using ImageIO (left) and libwebp (right) with a 10 second 480p30 animated WebP file. Decoding with libwebp is performed in realtime, completing in 10 seconds as expected; however, ImageIO decoding lags behind by more than 3 seconds, with the delay worsening over time.
After thorough investigation and profiling, we switched to using libwebp for WebP decoding through SDWebImageWebPCoder, an SDWebImage add-on. Though the change was small, it had a dramatic impact—our animated WebP issues disappeared completely.
Animation Detection & HandlingOne of our biggest challenges was reliably detecting and preserving animations. Previously, Discord identified animated content simply by looking at the GIF file extension. However, WebP and AVIF files can be either static or animated with no indication in their file extensions. This required several key infrastructure changes:
- Analyzing WebP and AVIF files during upload to detect animation status
- Storing and propagating animation metadata throughout Discord’s API and systems
- Respecting Discord’s accessibility preferences like Reduced Motion, ensuring animated WebP and AVIF files display as either still or animated based on user settings
Discord has historically relied on the piexif Python library to strip EXIF data from media files. However, we discovered that bugs in piexif were corrupting WebP metadata during the EXIF removal process, rendering the stored animated WebP files unplayable, even outside of Discord. This issue had persisted for years, affecting every animated WebP file uploaded to Discord. Special thanks to nico on Github for reporting this issue!
To address this problem, we submitted pull requests to fix these issues in the piexif library’s upstream repository:
https://github.com/hMatoba/Piexif/issues/145
https://github.com/hMatoba/Piexif/issues/144
The ImplementationBuilding on Open SourceOur journey to build support for modern image formats started with Lilliput, our open-source image processing library. While Lilliput has long supported GIF animations, WebP and AVIF presented unique challenges — these formats can contain either single or multiple frames, with their animation status determined by file-level metadata. This required significant changes to how Lilliput detects, reports, and transforms animations.
The initial work focused on supporting animated WebP, culminating in the release of Lilliput v1.3.1. The release was well-received by external users of Lilliput, sparking additional community contributions including GitHub Actions CI and native library support on Apple Silicon.
Phased Introduction of SupportWe rolled out support in phases, requiring careful coordination across multiple platforms:
Phase 1: Animated WebP Transformations for Web & Desktop
We began by adding animated WebP support to Lilliput and our Media Proxy service. This required two key changes: detecting animated images during metadata inspection of new attachments, and enabling on-the-fly transformations between animated and still variants. Both direct uploads through the Discord API and embedded links via Discord Unfurler use this metadata inspection process.
To track animation status, we added an [code]is_animated[/code] flag to message metadata persisted by the Discord API. This flag enables the Discord client to properly handle animated images, which need different processing than static ones.
Next, we updated Discord’s React Web & Desktop client to handle the new [code]is_animated[/code] flag. Since WebP and AVIF files can’t be identified as animated by file extensions or MIME types alone, we implemented animation flag checks throughout the app’s image handling logic.
Starting with Web and Desktop clients proved ideal for testing these backend changes. These platforms allowed quick iteration, fast deployments, and easy experimental rollouts through our feature flag system ( this is also possible on mobile, albeit with longer feedback cycles).
Phase 2: Mobile Animated WebP
Next, we added support for animated WebP attachments and embeds on mobile platforms. Android implementation was straightforward since WebP support is deeply integrated into the Android OS, while iOS proved to be more challenging as its built-in WebP support wasn’t performant enough for our needs. We rolled out the feature gradually on both platforms through an experiment.
While testing WebP performance on mobile, a parallel performance initiative at Discord switched all animated emoji serving to WebP instead of GIF. This change perfectly demonstrated the effectiveness of our work, especially the GIF-to-WebP transformation capabilities we’d added to Lilliput and Media Proxy. We’ll explore the performance impact of this change in detail later.
Phase 3: AVIF Support
Building on our animated WebP foundation, we expanded our stack to support AVIF. While WebP excels at web optimization, AVIF takes it further with superior support for high-quality photos and animations. Having faced similar technical challenges with both formats, we quickly integrated AVIF across our system.
AVIF support began by adding the AVIF-related dependencies to Lilliput: libyuv, aom, and libavif. These native code dependencies are compiled into binary libraries for Media Proxy to use in efficient image processing.
Next, we added support for AVIF detection and transformation in Lilliput’s C++ and Golang code. Since AVIF metadata and operations mapped cleanly to WebP, this integration was straightforward. After recently porting Media Proxy from Go to Rust, we only needed minor changes to interface the Rust Media Proxy with Lilliput’s AVIF-related code.
Finally, we implemented AVIF file-type support throughout the Discord app, following the same patterns we’d established with WebP.
Results and ImpactDramatic Size ReductionsThe transition to animated WebP has delivered significant performance improvements, particularly for animated emojis which are used throughout the Discord app on all platforms. This has numerous benefits for Discord users: less data to download, smaller on-device cache footprint, and higher probability of a cache-hit on device and on the Discord CDN.
- 29.39% reduction in median response size (from 31.3KB to 22.1KB)
- 42.54% reduction in 95th percentile response size (from 228KB to 131KB)
- Over 61% of emojis under 231KB are now smaller in WebP format, illustrated in the chart below showing the size of an animated emoji when transformed to a WebP vs. GIF
- More efficient rendering of WebP compared to GIF has enabled the display of dozens of animated emojis at 60 fps with no noticeable slow-down, something that was simply not possible with GIF.
- No noticeable loss in quality when converting most GIFs to WebP, with potential for significant reductions in file-size.
The rollout has seen remarkable uptake across our platforms:
- Over 95% of animated emoji requests now delivered in the WebP format
- Corresponding drop in legacy GIF emoji requests
- Smooth transition across all client platforms
Animated WebP support became available on all platforms from mobile release 252 onward on Nov 2, 2024. Retrieval of animated WebP attachments has increased by 39% between Dec 1, 2024 and Feb 18, 2025:
The number of AVIF attachments created each day has increased 33% over the last 30 days as support has expanded to cover all platforms:
Community ReceptionWe’ve received a lot of useful and positive feedback from Discord users throughout this process.
Closing ThoughtsLooking ForwardThe addition of animated WebP and AVIF support marks a significant milestone in Discord’s media infrastructure evolution — but it’s just the beginning. We’re actively exploring new ways to enhance the visual experience while maintaining the performance our users expect.
Some exciting areas we’re investigating:
- Enhancing HDR support by leveraging AVIF’s advanced color management. This will let us improve HDR AVIF images through tone-mapping to SDR when converting to 8-bit formats like WebP.
- Improving transformation speed for animated images. While we’ve successfully integrated animated WebP and AVIF into our image pipeline, these complex formats process more slowly than we’d like. We see opportunities to reduce transformation latency in both our Lilliput library and Media Proxy service.
- Supporting conversion from animated WebP and AVIF to GIF. We need to maintain GIF transformation support for compatibility with earlier app versions. This presents challenges due to GIF’s limited color depth and differences in format capabilities.
Modernizing Discord’s image format support has taught us valuable lessons about managing large-scale infrastructure changes while maintaining backwards compatibility. These insights position us well to evaluate and adopt new image technologies that will benefit our users.
If you’re interested in solving similar technical challenges at scale, we’re always looking for talented engineers to join our Media Infrastructure team. Check out our careers page to learn more.
( Press Release Image: https://photos.webwire.com/prmedia/7/335601/335601-1.jpg )
WebWireID335601
This news content was configured by WebWire editorial staff. Linking is permitted.
News Release Distribution and Press Release Distribution Services Provided by WebWire.