Batch compress images without color shifts
Measure the changes JPEG encoding causes and isolate the effect of stripping an sRGB tag.
Convert your working copies to sRGB with color management, keep the profile in the delivery exports, and test the same compression settings against lossless references before applying them to a folder. Compare matching pixels and inspect areas where color or edge detail matters. In the sample batch, the tagged and untagged JPEGs decoded to identical RGB under an sRGB assumption, while the JPEGs differed from their lossless references. That separates the effect of storing the tag from the effect of JPEG encoding for this batch. Test the files in the recipient’s viewer before making decisions about profile stripping.
What to look for
Use this guide when a set of pictures must get smaller and different members of the set appear to shift, dull or pick up color around edges. The change might appear only after sending the files to a browser, uploading them to a destination or opening the result in a different editor. Treat those observations as clues about where to measure. First compare the original and export with a single, known interpretation. Then compare what the destination actually shows.
A batch may contain photos, brand graphics and images with quiet gradients. These are different compression challenges. A smooth background can hide an average difference while a sharp border shows color spreading. Some simple graphics may already compress more efficiently in a lossless format. Inspect a representative file of each kind before picking a preset for the whole job.

Why it happens
Before you begin
The practice batch contains three 640 × 420 RGB references. The bowl crop comes from The Met’s public-domain photograph of Bowl, released under its Open Access program. The swatches are generated solid blocks with color labels. The gradient has small white text and narrow colored lines. Each source PNG has an sRGB profile. Its two JPEGs use identical quality, optimization and chroma subsampling settings. One includes the profile. Its partner has no embedded ICC information.
Use the downloads to compare the source and tagged version or view the contact sheet. The untagged comparisons are bowl, swatches and gradient. Keep your own originals and choose a lossless reference after any necessary orientation or color conversion. Compare equal-sized images so pixel coordinates carry the same meaning. Record the original profile before touching the files, especially when a folder mixes files from phones, a designer and a scanner.
An ICC profile records an interpretation of the numeric color channels. Converting a known source profile to sRGB can change the pixel values to preserve color appearance in the destination space. Removing metadata leaves the destination to pick an interpretation for those values. Those actions have different consequences. In this lab the values were already in sRGB before the tag was removed from one copy.
Steps
Choose test images and define the color reference.
Select files that would expose the defects you care about. The photo supplies texture and soft light, the swatches present consistent color next to sharp borders, and the gradient includes a dark caption box plus fine detail. For your batch also include any exact brand colors or background shades used repeatedly. Note where those measurements should be taken. If the crop or output size has to change, create your lossless reference after the crop or resize and use that same file for the subsequent tests.
- Open the references in one color-managed program.
- If a source has a known profile different from sRGB, use Convert to Profile with sRGB as the destination and then save that profile.
- If a file has no profile and no known source space, find out how it was made or consult an approved appearance before processing it.
- Simply choosing a different interpretation can change how the file looks when it opens.
Create a small compression trial with one variable at a time.
Export new files from the lossless references. This trial used Pillow JPEG quality 76, optimization enabled and 4:2:0 chroma subsampling. The script saves two files per reference, with identical settings except for the presence of the sRGB ICC tag. Keep each variant under a clear name. Avoid changing resize or color settings between these two versions. Reopen them from disk before evaluating the batch.
- If your destination uses another format, run the corresponding experiment in that format.
- Numeric quality values describe an encoder’s controls and cannot be assumed equivalent across tools.
- Keep the same dimensions and profile in the initial trial and choose the level after comparing the measured results.
- Save the exact settings beside the files that passed, including whether optimization or a subsampling setting was enabled.
Check per-channel differences at matching positions.
Decode both files at their actual dimensions. Convert within the same known color space if needed. For each channel, subtract the corresponding source and output values, take the absolute difference and average across all pixels. Mean absolute RGB is sensitive to changes in either direction. The source-versus-tagged JPEG for the bowl measured R 1.3397, G 1.1964 and B 1.4929 per pixel. The blue-channel average for the gradient was 2.1144. These values summarize channel steps in the saved examples. They do not describe a threshold for acceptable color across products.
- Also inspect a known color patch in an interior region and an important edge at the same zoom.
- Averaging over the entire picture can hide edge artifacts.
- A large flat background can dominate the result even when a small logo is affected.
- Use the sample comparison to find the caption and the orange lines, then open the individual source and export to look at those features more closely.
Use the tagged and untagged copies to isolate an interpretation change.
In this trial the raw JPEG pixel arrays matched byte for byte between the two profile variants. The measurement then interpreted the tagged file through sRGB and left the untagged file under the same assumption. Every picture in that comparison measured zero mean absolute difference in all channels. The ICC tag added 606 bytes to each file, based on the matching encoded pairs. This is a measured result for sources already in sRGB and the interpretation used here.
- If the receiving application makes another assumption for an untagged file, compare what it shows using a tagged copy as the reference.
- If the receiving system strips incoming profiles, supplying converted sRGB pixel values can reduce the ambiguity.
- Inspect the served or returned file if you have access.
- Keep the original profile or a tagged master in your source folder for later use.
Choose exports file by file and run the folder.
Compare the actual bytes of your trial exports. The sample bowl source fell from 214,412 bytes to 18,249 with the tag, and the gradient from 13,753 to 12,322. The swatch PNG was only 11,028 bytes, while its tagged JPEG grew to 15,556. In that case the source is both smaller and lossless. If your destination accepts PNG, preserve the PNG for that type of image. Use your approved settings for the images that benefit and keep a mapping from inputs to outputs.
- Reopen the final folder, check that each expected name is present, and sample the photos at the destination’s likely viewing size.
- Inspect any outlier where bytes grow or a colored edit band appears.
- Go back to the lossless reference and retry with settings that preserve the difficult parts.
- A batch may deserve more than one output preset even when every file goes to the same destination.
Check your result
The test reopened all nine files. For each reference it verified the common dimensions, checked that the tagged JPEG contained the reference’s sRGB profile, and checked that the paired JPEG contained no embedded profile. It compared raw decoded pixels across the pairs before calculating the mean changes against the references. The table below records all three per-channel measurements. The comparison image is made from the reopened files so you can locate the areas used in the visual review.
For your work, record the original and exported byte sizes and the embedded profile alongside the comparison. Check both a neutral area and important saturated edges. Reopen the exact copy you will hand over rather than an editor preview. When the destination does its own rendering or transcoding, inspect a representative output there. If a defect appears only there, check its displayed size and file interpretation before changing all the local exports.
| Reference | Source bytes | Tagged bytes | Untagged bytes | Reference vs tagged mean absolute RGB | Tagged vs untagged mean absolute RGB |
|---|---|---|---|---|---|
| bowl-reference.png | 214412 | 18249 | 17643 | 1.3397 / 1.1964 / 1.4929 | 0 / 0 / 0 |
| swatches-reference.png | 11028 | 15556 | 14950 | 1.6196 / 0.8952 / 1.8545 | 0 / 0 / 0 |
| gradient-reference.png | 13753 | 12322 | 11716 | 1.5017 / 0.8304 / 2.1144 | 0 / 0 / 0 |
Common mistakes
Removing the profile before converting from a known color space. Convert the working copy to the intended space first and confirm its profile when it reopens.
Comparing a resized output with an unchanged master. Save a lossless reference at the intended crop, orientation and dimensions before testing compression.
Judging color by file size alone. Check a reference patch, edge behavior and the preview under a known profile as well as the saved byte count.
Applying one lossy preset to flat graphics and photos. Inspect the individual file results. The swatch PNG was smaller than its JPEG in this trial.
Limitations
The measured inputs are small sRGB test images. One color profile and one JPEG preset were evaluated. The numeric comparison models a destination that interprets the untagged files as sRGB. The experiment does not measure wide-gamut displays, third-party transcodes or the color accuracy of a particular monitor.
Test record
Tested on 2026-11-23 with Pillow 13.0.0 under Python 3.14.4. The identical JPEG settings gave equal decoded RGB arrays with and without the sRGB tag. Source versus JPEG differences were nonzero for each picture, and the flat-color PNG was smaller than either JPEG.
The measurement record lists the local outputs and their SHA-256 digests.
Tested in
Questions
Do I need the sRGB tag if the untagged copy looks identical?
Keep the tag when the delivery supports it, so the file carries its intended interpretation. The measured equality assumes sRGB for both versions.
Why did my flat-color image grow after JPEG export?
Lossless PNG can compress repeated colors very efficiently. Compare the saved alternatives with the same dimensions and choose a format the destination accepts.
Can a small mean difference hide a damaged logo?
Yes. A small edge can occupy little space in the full-image mean. Review important patches and sharp details as well as the aggregate measurement.
Should I change the JPEG preset after an upload looks different?
Compare the local file and the uploaded version under the same viewing conditions first. Find out whether resizing, color interpretation or downstream encoding explains the observed difference.