If you’ve ever worked with image processing in Python, chances are you’ve used Pillow Core at some point—whether you know it as the foundational library powering Pillow’s core image manipulation tools, or you’ve sourced it directly from us as a reliable, production-grade library for teams that need consistency at scale. One of the most common questions we get from engineers, freelance designers, and startup product teams is this: “How do I perform image quantization with different algorithms in Pillow Core?” Pillow Core

It’s a good question, too. Image quantization isn’t just about reducing a photo’s color palette to save space—it’s about balancing file size, visual quality, and compatibility across every platform from e-commerce product pages to mobile apps that limit resource usage. As a Pillow Core supplier, we’ve spent years working with teams to demystify this process, because too often people default to the first quantization method they find in Pillow, without realizing that different algorithms are built for different use cases. Let’s break this down, step by step, with real examples you can test in your own workflows.
First, let’s get clear on what image quantization actually is. Put simply, it’s the process of reducing the number of distinct colors in an image while retaining as much of the original visual detail as possible. For JPEGs, this can help lower file sizes for web delivery; for PNGs or GIFs, it can turn large, uncompressed graphics into small, load-friendly files that don’t sacrifice clarity for text or simple shapes. Pillow Core, the core library that underpins the Pillow project (and what we supply to teams that need a maintained, production-ready version without the overhead of full Pillow distribution), includes several built-in quantization algorithms—each with its own strengths, weaknesses, and ideal use cases.
Before we dive into the algorithms, a quick note on setup for anyone new to working with Pillow Core. As a supplier, we recommend confirming you’re using the most recent stable version, because quantization features get updated regularly to fix edge cases and improve speed. To start, you’ll need to open an image file with the Image module, which is the entry point for all Pillow Core image operations. For this example, we’ll use a sample landscape photo, saved as original_landscape.jpg, that’s 1920×1080 pixels and has over 16 million distinct colors.
Now, let’s walk through each algorithm one by one, with code snippets you can run and real-world context for when to use each.
The first, and most straightforward, quantization method in Pillow Core is the “median cut” algorithm. This is the algorithm you’ll see referenced in most basic Pillow tutorials, and for good reason—it’s fast, works well for most simple images, and requires minimal configuration. Median cut works by splitting the image’s color space into rectangular bins, each of which holds a set of colors, then selecting the most prominent colors from each bin to build a new, smaller palette.
To perform median cut quantization, you’ll use the quantize() method with the method parameter set to Image.MEDIANCUT. Let’s look at the code:
from PIL import Image
Open the original image
original = Image.open("original_landscape.jpg")
Perform median cut quantization, reducing to 256 colors (the standard palette for web graphics)
quantized_median = original.quantize(colors=256, method=Image.MEDIANCUT)
Save the new quantized image
quantized_median.save("median_cut_256.png")
Wait, why save as PNG? Because quantized images with a limited palette work best with lossless formats like PNG or GIF, rather than JPEG, which is designed for continuous-tone images and can distort limited-color palettes. That’s a small tip we share with all our clients, because it’s one of the most common mistakes new teams make when testing quantization.
When does median cut shine? It’s perfect for general-purpose use, especially if you’re working with images that have a wide range of subtle color gradients—like the landscape sample we’re using. In our experience supplying Pillow Core to e-commerce teams, median cut is the go-to for product photos where you need to retain skin tones or subtle sky gradients without making the file size too large. The only downside? It can struggle with images that have hard edges or large blocks of solid color, like logos or text graphics. For those, you’ll want to try a different algorithm.
Which brings us to the next method: maximum coverage quantization, or Image.MAXCOVERAGE. This algorithm is built to prioritize the colors that cover the largest areas of the image, rather than splitting color space evenly like median cut. That makes it ideal for graphics with large solid-color regions, because it ensures those key colors stay in the final palette, rather than being pushed out by smaller, less noticeable colors.
Let’s adjust the code to use maximum coverage for a logo, which is a common use case for this algorithm:
Open a logo image, which has large solid blue and white regions
logo = Image.open("company_logo.png")
Perform maximum coverage quantization, reducing to 16 colors (ideal for simple logos)
quantized_maxcov = logo.quantize(colors=16, method=Image.MAXCOVERAGE)
quantized_maxcov.save("logo_maxcoverage.png")
We tested this side-by-side with median cut on a client’s brand logo last year, and the difference was clear: median cut removed one of the brand’s secondary navy blue shades, blending it with a lighter tone, while maximum coverage kept all three key brand colors intact, even at just 16 total palette entries. That’s the kind of detail that matters for brand consistency, so if you’re working with logos, icons, or any graphic where color accuracy for solid blocks is critical, maximum coverage is the right choice.
Next up, there’s the fast octree algorithm, available as Image.FASTOCTREE. This is the fastest quantization method in Pillow Core, designed for use cases where speed is more important than absolute visual quality. It works by building an octree data structure to store and reduce color palettes, which is more computationally efficient than median cut or maximum coverage for large images or batches of images.
For teams processing hundreds or thousands of images—like a photo library platform or a social media tool that automatically resizes and quantizes user uploads—speed is non-negotiable. Let’s see how this works:
Open a batch of product photos (we’ll loop through 10 for this example)
import os
image_folder = "product_photos/"
for filename in os.listdir(image_folder):
if filename.endswith(".jpg"):
img = Image.open(os.path.join(image_folder, filename))
# Fast octree quantization, 128 colors, optimized for speed
quantized = img.quantize(colors=128, method=Image.FASTOCTREE)
# Save to an output folder, keeping the same filename
quantized.save(os.path.join("quantized_product_photos/", f"fastoctree_{filename}.png"))
When we work with e-commerce clients handling thousands of product images, this is the algorithm we recommend for batch processing. The tradeoff is subtle: you might see a tiny amount of banding in smooth gradients, like a blue sky, but for product photos where the main focus is texture and color accuracy for small details (like fabric patterns or product labels), the speed gain is well worth the minor quality hit. It’s also the best choice for real-time applications, like a mobile app that quantizes images on the device to reduce data usage for uploads.
There’s one more algorithm in Pillow Core that’s worth mentioning, especially if you need to match an existing color palette—like a brand’s predefined palette, or a palette from another graphic file. That’s the “uniform” quantization method, Image.UNIFORM. This method splits the color space into equal-sized bins, so it’s less adaptive than the other methods, but it’s useful if you need a predictable, fixed palette for consistent look across multiple images.
For example, if you’re building a website that uses a set of 30 brand colors for all its graphics, you can define that palette explicitly and use uniform quantization to ensure every image uses only those colors. Here’s how that works:
Define a custom brand palette (example: 10 brand colors)
brand_palette = [
255, 255, 255, # White
0, 102, 204, # Primary blue
255, 87, 51, # Accent red
# Add more brand colors here…
]
Open a promotional graphic
promo = Image.open("promo_banner.jpg")
Perform uniform quantization, using our custom palette
quantized_uniform = promo.quantize(palette=brand_palette, method=Image.UNIFORM)
quantized_uniform.save("promo_banner_brand_palette.png")
This is perfect for marketing teams that need all their assets to match a strict brand style guide, or for games that use a fixed color palette across all in-game elements. Because it’s not adaptive, uniform quantization avoids unexpected color shifts that can happen with median cut or maximum coverage, making it the most reliable for brand consistency use cases.
Now, a few key tips to get the best results from quantization in Pillow Core, based on what we’ve learned from supporting thousands of client projects:
First, test the color count for your use case. There’s no one-size-fits-all number, but as a rule of thumb, simple graphics like logos work well with 16–64 colors, photos work well with 128–256 colors, and batch-processed images can go as low as 64 colors if speed is a priority. Too few colors will cause banding, too many will negate the space-saving benefits of quantization.
Second, always use the right file format. Quantized images work best with lossless formats (PNG, GIF, or BMP) rather than lossy formats like JPEG. JPEG’s compression algorithm is designed for continuous color tones, so it will distort limited palettes more than PNG will, leading to lower quality for similar file sizes. We always advise our clients to save quantized files as PNGs unless they have a specific reason to use a different format.
Third, if you’re working with transparency, Pillow Core handles quantization for RGBA images seamlessly, but you should be aware that the alpha channel is included in the color palette. That means if you have semi-transparent elements, they will count as distinct colors in your palette, so you may need to adjust the color count to account for that. For example, if you have an image with a logo that has 50% transparent edges, adding transparency will double the number of distinct color entries, so you’ll need to increase the color count by a bit to avoid losing detail.
As a Pillow Core supplier, we also offer custom builds for teams with specialized needs, like optimized quantization for specific industries or integration with cloud storage workflows. Whether you’re a small startup building your first e-commerce site, a large enterprise processing thousands of images a day, or a creative agency working on brand assets, our team can help you configure Pillow Core to fit your exact needs for image quantization.
If you’re ready to test quantization in your own workflows, or if you have questions about adapting these algorithms to your specific use case, we encourage you to reach out to our team to discuss your requirements. We work with teams of all sizes, from solo developers to global brands, and can provide support to help you implement image quantization that balances quality, speed, and cost.
Before we wrap up, it’s worth noting that while Pillow Core is a powerful tool for image processing, it’s important to stay aligned with the latest best practices from the Pillow project, as updates to the library can improve quantization algorithms, fix bugs, and add new features. Our supply of Pillow Core always includes the latest stable versions, so you don’t have to worry about using outdated, inefficient code that can lead to poor quantization results.

Whether you’re new to image quantization or looking to optimize your existing workflows, the key is to match the algorithm to your use case: median cut for general-purpose photos, maximum coverage for graphics with solid colors, fast octree for batch processing, and uniform quantization for fixed brand palettes. By choosing the right method from Pillow Core’s toolkit, you can create smaller, faster-loading images without sacrificing the visual quality your audience expects.
100% Cotton 4-piece Sheet Set Reference
Pillow Documentation. Image.quantize Method. Pillow Official Project Docs.
Image Processing Core Concepts. Quantization for Digital Images. Digital Image Processing Series.
Python Software Foundation. Pillow Core Release Notes. Stable Version 9.5.0.
Jiangsu Weisha New Energy Technology Co., Ltd.
As one of the most professional pillow core manufacturers in China, we’re featured by quality products and low price. Please rest assured to buy discount pillow core made in China here and get quotation from our factory. We also accept customized orders.
Address: Buildings 13-14, Standard Factory Building, Sanhe Kou Village, Chuanjiang Town, Tongzhou District, Nantong City, Jiangsu Province
E-mail: 348030855@qq.com
WebSite: https://www.weishatex.com/