Sub topic 5
Handle transparency and flattening
This chapter assumes you know how layers work, what a raster image is, and how to open the Export As dialog. It covers how Photoshop represents transparency, which web formats can keep it, and what happens when a format cannot. It also covers the errors that show up most often in exported files.
What transparency is in a Photoshop document
Transparent pixels in a layer have an alpha value below 100%. Alpha is a fourth channel stored next to red, green, and blue. An alpha of 0% means the pixel is fully see-through, and 100% means it is fully opaque. Values in between are partial transparency, which is how soft shadows and anti-aliased edges work.
The checkerboard pattern on the canvas means there are no pixels at that spot. It is not part of the image. You see it only when every layer under that spot is empty or hidden, including the Background layer.
Two things are easy to confuse:
- Layer opacity is a slider on a layer. It scales the alpha of the whole layer.
- Pixel transparency is stored per pixel. A layer at 100% opacity can still contain transparent pixels.
Both affect the exported result. When you export, Photoshop composites all visible layers into one image and writes the combined alpha to the file, if the format can store it.
Which formats can keep transparency
| Format | Transparency | Notes |
|---|---|---|
| JPEG | None | No alpha channel. Transparent areas are filled with a solid color. |
| PNG | Full 8-bit alpha | Partial transparency works. Best choice for logos, icons, and cutouts. |
| GIF | 1-bit only | A pixel is either fully transparent or fully opaque. Edges look jagged. |
| SVG | Yes | Vector format. Photoshop exports it only from vector content, and it is not a general raster export. |
| WebP | Full 8-bit alpha | Supports lossy and lossless modes, both with alpha. |
JPEG is the format that causes the most surprises. If you export a cutout as JPEG, Photoshop must replace the transparent pixels with something. In Export As, that is the canvas color setting. In Save for Web (Legacy), it is the Matte color. Both default to white, which looks fine on a white page and wrong on any other background.
Flattening: what it means and when it happens
Flattening merges all visible layers into a single layer and removes transparency by filling it with a background color. Photoshop does this to your exported copy when the format requires it. Your PSD is not changed by an export.
There is an important difference between flattening a document and exporting it:
- Image > Flatten Image changes your open document. Hidden layers are discarded. Undo it right away if you did not mean to run it.
- Export produces a new file and leaves the layered document alone. The flattening happens inside the exported copy.
Avoid running Flatten Image before an export. It gains you nothing and removes your ability to edit.
Exporting a transparent PNG
For a file that keeps its transparency, follow these steps:
- Make sure the Background layer is hidden or deleted. A Background layer is always opaque and will fill the whole canvas. To change it, double-click it in the Layers panel and click OK to convert it to a normal layer.
- Hide any layer that should not appear, such as guides or a white test fill.
- Choose File > Export > Export As.
- Set Format to PNG and make sure Transparency is checked.
- Check the preview. The preview shows a checkerboard where the image is transparent.
- Click Export.
If the Transparency box is unchecked, Photoshop fills transparent areas with the canvas color. The result is an opaque PNG with a solid background.
Trim transparent pixels around an object
A logo placed on a large canvas exports with a lot of empty space. The file is bigger than needed, and the image sits off-center when placed in a web page.
Use Image > Trim, choose Transparent Pixels, keep all four sides checked, and click OK. Photoshop crops the canvas to the nearest non-transparent pixel. Trim changes your document, so run it on a copy, or press Undo after the export. Trim ignores nearly transparent pixels only if they are exactly 0% alpha. A faint shadow of 1% alpha will keep the canvas large.
If you want some padding around the object, apply Image > Canvas Size afterward. Enter the new size, and the new area stays transparent as long as the Canvas extension color is set to Transparent. That option is not available on a Background layer.
Choosing a matte color for JPEG
When you must use JPEG for a cutout, for example because a platform rejects PNG, match the fill to the destination. Soft edges are the trap. Anti-aliased edge pixels are a blend of the object and transparency, and they blend with the matte color on export. A white matte on a dark page leaves a light fringe, often called a halo.
Choose a matte close to the page background. For a known solid background, put a fill layer of that color under your artwork. Then the edge pixels blend against the right color before the export. This is more predictable than relying on the canvas color setting.
Semi-transparent edges and GIF
GIF stores each pixel as fully transparent or fully opaque. A soft shadow or an anti-aliased curve has partial alpha, so GIF has to round each pixel one way or the other. The result is stair-stepped edges, and a white fringe if the matte does not fit the page.
In Save for Web (Legacy), the Transparency option and the Matte menu control this. Set the matte to the page color, and use Dither to simulate soft shadows. For anything other than a simple animation, PNG or WebP gives cleaner results at a similar or smaller file size.
Common errors and how to spot them
- Black background in the result. Often a transparent PNG opened in a viewer that does not draw a checkerboard. Test the file on a page with a colored background before you assume it is wrong.
- White rectangle behind a logo. The Background layer was still visible, or the Transparency box was off.
- Halo around a cutout. The matte color or the color the edges were blended against does not match the page. Rebuild the edge against the right color or switch to PNG.
- Large file for a small logo. The canvas has a lot of empty area. Trim it. Also check for nearly invisible pixels from a soft brush or a faint layer effect.
- Color shift on semi-transparent areas. Layer blend modes other than Normal interact with what lies beneath them. If the layer beneath is transparent, the blend result can differ from what you saw on the canvas. Check the preview.
- Missing shadows. A drop shadow from layer styles appears only if the layer is visible and the shadow stays inside the canvas bounds. Extend the canvas or trim after you add padding.
Transparency check in code
A quick way to verify that an exported PNG really has an alpha channel is a short script. This one uses Python with the Pillow library, which you can install with pip install pillow.
from PIL import Image
import sys
path = sys.argv[1]
img = Image.open(path)
print("mode:", img.mode)
has_alpha = img.mode in ("RGBA", "LA") or "transparency" in img.info
print("has alpha channel:", has_alpha)
if img.mode == "RGBA":
alpha = img.getchannel("A")
low, high = alpha.getextrema()
print("alpha range:", low, "to", high)
print("fully opaque:", low == 255)Run it as python check_alpha.py logo.png. A mode of RGBA with an alpha range starting at 0 means the file keeps real transparency. If fully opaque prints True, the transparent area was filled during export.
Summary of decisions
- Does the image need see-through areas? If yes, use PNG or WebP.
- Is it a photo with no transparency? Use JPEG or lossy WebP and flatten only in the exported copy.
- Will the file sit on a known solid color? A matte or fill layer of that color gives clean edges in any format.
- Is the canvas bigger than the object? Trim, then add padding on purpose.
Exercise
You export a logo with a soft drop shadow as a JPEG at quality 80. On your site's dark gray page, the logo sits in a white box with a light halo around the shadow. Give two causes and two ways to fix it.
Show answer
Causes: JPEG has no alpha channel, so the transparent area was filled with the default white matte, and the soft shadow edges were blended against white. Fixes: (1) export as PNG or WebP with Transparency enabled so the alpha is kept, or (2) if JPEG is required, put a fill layer in the page's dark gray beneath the artwork, or set the matte to that color, then export.
Exercise
A transparent PNG exported from Photoshop shows a white background when you check it. List the three things you would check in Photoshop, in order.
Show answer
First, check that the Background layer is hidden or converted to a normal layer. Second, check that no visible layer contains a white fill. Third, check that Transparency is turned on in the Export As dialog for PNG. You can then confirm the result with the Pillow script: an alpha range that starts at 255 means the file is fully opaque.