AutoCrop

How to trim transparent pixels in Photoshop

Photoshop trims transparent borders with Image > Trim. It takes about five seconds once you know where it lives — and it has one hard limitation that catches everyone working with drop shadows.

Trim it in the browser instead

No install, no upload, adjustable threshold for soft shadows.

Open AutoCrop

Trimming transparent pixels, step by step

  1. 1

    Open the file and make sure the layer is unlocked

    Trim reads the flattened composite. A locked background layer is opaque by definition, so if your file has one, Trim will find no transparent pixels to remove.

  2. 2

    Choose Image > Trim

    The dialog offers Transparent Pixels, Top Left Pixel Color and Bottom Right Pixel Color, plus checkboxes for which sides to trim.

  3. 3

    Select Transparent Pixels

    This is the option that reads the alpha channel. The two Pixel Color options sample a corner and trim everything matching it exactly — with no tolerance setting, so they are unreliable on anything antialiased.

  4. 4

    Leave all four sides checked, then click OK

    Top, Bottom, Left and Right are all ticked by default. Uncheck one to keep that margin — useful when a design depends on padding on a particular side.

  5. 5

    Export with File > Export > Export As

    Choose PNG and keep Transparency ticked. Save As with PNG works too; Export As gives you the size preview and metadata options.

What the three Trim options actually do

OptionWhat it removesWhen to use it
Transparent PixelsBorder rows and columns where every pixel has an alpha value of exactly 0.The right choice for any PNG with transparency. This is the true trim.
Top Left Pixel ColorBorder pixels exactly matching the colour of the top-left pixel.A flat, uniform, non-antialiased background — a solid-colour export, for instance.
Bottom Right Pixel ColorThe same, sampling the bottom-right pixel instead.When the top-left corner happens to contain content but the bottom-right does not.

The drop shadow problem

Trim with Transparent Pixels keeps any pixel whose alpha is above zero. For a flat logo that is precisely correct. For a logo with a 30-pixel blurred shadow it means keeping a 30-pixel band of pixels you cannot see — alpha values of 1, 2, 3 — because they are, strictly speaking, not transparent.

The result looks like Trim failed. It did not; it did exactly what it promises. There is just no setting for “ignore anything under 20 percent opacity”. Your options in Photoshop:

  • Hide the shadow layer, run Trim, then re-enable it — but the shadow now extends past the canvas and gets clipped on export.
  • Reduce the shadow’s blur or spread so its faint tail is shorter, changing the design.
  • Trim, then crop manually by eye to cut into the shadow — repetitive and not reproducible.
  • Use a tool that exposes an alpha threshold, and choose how much of the shadow to keep.

For reference, on a 340 × 340 shadowed icon a threshold of alpha > 5 — roughly what Photoshop does — yields 262 × 270, while alpha > 96 yields 216 × 224, the visible disc. The full table is here, and the tool comparison covers the trade-offs.

Batching it with an Action

For a folder of files, record the operation once and let Photoshop repeat it:

  1. 1

    Create a new Action

    Open the Actions panel (Alt/Option + F9), create a set, then a new Action, and press record.

  2. 2

    Perform the steps once

    Run Image > Trim with Transparent Pixels, then File > Export > Export As or Save As, then close the document. Stop recording.

  3. 3

    Run it over the folder

    File > Automate > Batch, pick your Action, set Source to the folder and Destination to where the results should go. Tick “Override Action Save As Commands” if your Action includes an export step, or the destination will be ignored.

It is reliable, and it requires a Photoshop licence and a machine with it open. For a scripted pipeline, ImageMagick is a better fit; for a one-off folder, batch trimming in the browser needs no install at all.

Photoshop trimming: questions

Where is Trim in Photoshop?
Image > Trim, directly under Image > Crop in the same menu. It is not in the toolbar and has no default keyboard shortcut, which is why it is easy to miss.
Why is Trim greyed out or doing nothing?
Usually because the layer is a locked background layer, which is fully opaque and therefore has no transparent pixels to trim. Convert it to a normal layer first. Trim also does nothing if the artwork already touches all four edges.
Does Photoshop Trim have a tolerance or threshold setting?
No. Transparent Pixels keeps any pixel with an alpha value above zero, and the two Pixel Color options match a colour exactly. There is no way to tell Photoshop to ignore pixels below a given opacity, which is the main limitation of the command.
How do I trim many PNGs in Photoshop?
Record an Action containing Image > Trim and your export step, then run File > Automate > Batch over a folder. It works, but it needs Photoshop open on every machine that runs it.
Why does Trim leave a margin around my drop shadow?
Because it is not a margin — it is the shadow. A blurred shadow fades to alpha values of 1 or 2 over dozens of pixels, and Trim keeps every pixel above zero. Hiding the shadow layer before trimming, or using a tool with a threshold, are the two ways around it.