Sub topic 9
Saving JPEG: quality, compression artifacts, and the flattened result
This chapter assumes you can already create and open documents, know what layers are, and have saved a layered PSD. It covers what a JPEG stores, how the quality setting changes the result, the errors that show up most often, and how to script the save.
What a JPEG is
JPEG (Joint Photographic Experts Group) is a lossy raster format. Lossy means the file stores an approximation of your image, and the discarded detail cannot be recovered. JPEG suits photographs because it throws away the kind of detail the eye notices least: fine variations in color and subtle texture.
A JPEG keeps one flat grid of pixels. It does not keep:
- Layers, masks, adjustment layers, smart objects, or text layers.
- Transparency. JPEG has no alpha channel, so every pixel must have a solid color.
- Extra channels, paths, and most editing state.
It can keep an embedded color profile and metadata such as EXIF (camera data) and copyright fields.
How the compression works
Knowing the mechanism helps you predict where artifacts will appear.
- The image is converted to luminance (brightness) and chrominance (color) channels. The eye is more sensitive to brightness, so color detail is reduced first (chroma subsampling).
- The image is divided into 8 by 8 pixel blocks.
- Each block is transformed into frequency components, and the small, high-frequency components are rounded away. A lower quality setting rounds away more.
- The remaining values are compressed losslessly.
Because of the block structure, errors appear along block edges and around sharp contrast.
Compression artifacts
| Artifact | What it looks like | Where it appears |
|---|---|---|
| Blocking | Visible 8 by 8 squares | Smooth gradients such as sky, at low quality |
| Ringing (mosquito noise) | Speckles or halos near edges | Text, thin lines, high-contrast edges |
| Color bleeding | Colors smear past edges | Saturated red or blue against neutral areas |
| Banding | Stepped bands in a gradient | Dark or smooth gradients |
Screenshots, logos, and text suffer most because they have hard edges and flat color. Those images are better as PNG (see the PNG chapter).
Generation loss
Each time you open a JPEG, edit it, and save it as a JPEG again, the encoder re-quantizes the image and adds new error. This is generation loss. After several rounds, artifacts accumulate.
Avoid it with this workflow:
- Keep a layered PSD (or the original camera file) as the master.
- Make all edits in the master.
- Produce each JPEG as a fresh output from the master.
Never use a previously saved JPEG as your master.
The flattened result
When you save a layered document as JPEG, Photoshop merges the visible layers into one. Hidden layers are discarded from the output. Where the document has transparent areas, Photoshop fills them with the Matte color you choose in the JPEG Options dialog (white by default).
Save As versus Save a Copy
If you use File > Save As and choose JPEG with a layered document open, Photoshop shows a warning that layers will be flattened. Two behaviors follow:
- With As a Copy checked (or via Save a Copy), the open document keeps its layers and its name. You get a flat JPEG on disk.
- Without it, the open document is renamed to the JPEG, and you risk closing it without having saved the layered version.
Always save the PSD first, then make the JPEG as a copy.
The JPEG Options dialog
After you choose a name and format, the JPEG Options dialog appears.
Quality
Quality runs from 0 (smallest file, worst quality) to 12 (largest file, best quality) in the Save As dialog. It also appears as a Low-to-Maximum menu. Export As and Save for Web use a 0 to 100 percent scale instead. The scales are not interchangeable, and exact equivalences depend on the version.
| Save As value | Typical use |
|---|---|
| 12 | Archival-quality JPEG, large files |
| 10 | High quality for photos, good default for web masters |
| 8 | Good balance for general web use |
| 5 or lower | Visible artifacts, thumbnails only |
Test your own images. File size does not fall in a straight line. The drop from 12 to 10 is often large, while the gains below 6 are small and the damage is visible.
Matte
The matte color replaces transparent pixels. Choose a color that matches the page background to avoid halos on semi-transparent edges.
Format Options
| Option | Behavior |
|---|---|
| Baseline (Standard) | Loads top to bottom. Most compatible. |
| Baseline Optimized | Smaller file at the same quality. Widely compatible. |
| Progressive | Loads as a blurry full image that sharpens. Slightly different file size, and supported by modern browsers. |
Embed Color Profile
Embedding the profile (usually sRGB) lets software display colors as intended. For web delivery, convert to sRGB first using Edit > Convert to Profile. Otherwise a wide-gamut image (such as Adobe RGB or Display P3) can look dull or oversaturated in programs that ignore profiles.
Color mode and bit depth
JPEG supports RGB, CMYK, and grayscale, in 8 bits per channel only. If your document is 16-bit, Photoshop may gray out JPEG in the Save As list or convert to 8-bit on save. Convert it yourself with Image > Mode > 8 Bits/Channel so you control the result. CMYK JPEGs often display incorrectly in browsers, so use RGB for the web.
Common errors
- JPEG missing from the format list. The document is probably 16-bit or 32-bit. Convert to 8 bits per channel.
- Black or white edges around a cutout. Transparent areas were flattened onto the wrong matte. Set the matte to the destination background, or use PNG.
- Dull colors in the browser. The file was saved in a wide-gamut or CMYK profile without conversion to sRGB.
- Layers gone after closing. The document was saved over with Save As and no PSD copy exists.
- Blocky gradients. The quality was too low, or the image was re-saved several times. Re-export from the master at a higher quality.
- File too large. Reduce pixel dimensions first. Resizing usually saves more than lowering quality.
Worked example: export a photo for the web
- Save the layered master as
banner.psd. - Choose Image > Mode > 8 Bits/Channel, if needed.
- Choose Edit > Convert to Profile and pick sRGB.
- Choose File > Save a Copy, set the format to JPEG, and confirm.
- In JPEG Options, set Quality to 8 to 10, Format Options to Baseline Optimized or Progressive, and keep Embed Color Profile on.
- Open the result at 100 percent zoom and inspect edges and gradients.
Scripting a JPEG save
The following ExtendScript writes a JPEG copy of the active document, the same way Save a Copy does.
// ExtendScript: save a JPEG copy of the active document
var doc = app.activeDocument;
var jpegOpts = new JPEGSaveOptions();
jpegOpts.quality = 10; // scale is 0 to 12
jpegOpts.embedColorProfile = true;
jpegOpts.formatOptions = FormatOptions.STANDARDBASELINE;
jpegOpts.matte = MatteType.WHITE;
doc.saveAs(new File("~/Desktop/banner.jpg"), jpegOpts, true, Extension.LOWERCASE);The third argument, true, is the as-a-copy flag. The open document keeps its layers and name. Set formatOptions to FormatOptions.PROGRESSIVE and add jpegOpts.scans = 3 for a progressive file.
Summary of the decision
Exercise
You have a layered document with a logo on a transparent background and a soft drop shadow. A teammate saved it with File > Save As > JPEG and found a white box around the logo and no layers left in the open document. Explain both problems and how to produce the right outputs.
Show answer
JPEG has no alpha channel, so Photoshop filled the transparent areas with the matte color, white by default, which gives the white box. The shadow's semi-transparent pixels were blended against white too. Save As without "As a Copy" also renamed the open document and flattened the saved file, so layers are not stored in the JPEG. To fix it, save the layered master as a PSD, then export the logo as a PNG to keep transparency. If a JPEG is required, set the matte to the page background color and save with Save a Copy so the open document keeps its layers.
Exercise
A 16-bit Adobe RGB photo will not show JPEG in the Save As list. Which steps make a web-ready JPEG, and why is each needed?
Show answer
Convert to 8 bits per channel with Image > Mode > 8 Bits/Channel, because JPEG stores only 8 bits per channel. Use Edit > Convert to Profile to convert to sRGB, so browsers show the colors correctly. Then use Save a Copy as JPEG at quality 8 to 10 with Embed Color Profile on, so the layered master stays unchanged.