TechEarl

How to Convert a PSD to PNG From the Command Line

Convert a PSD to PNG from the command line with ImageMagick. The one trick that matters: design.psd[0] selects the flattened composite, so you get one PNG instead of a folder full of separate layers.

Ishan Karunaratne⏱️ 7 min readUpdated
Share thisCopied
Convert a PSD to PNG from the command line with ImageMagick using the [0] composite-layer trick, extract individual layers, batch a folder, and the Maximize Compatibility caveat.

To convert a PSD to PNG from the command line, the command you want is magick "design.psd[0]" design.png. The [0] is the whole trick: it selects the merged, flattened composite that Photoshop saves inside every PSD, so you get a single PNG of the artwork as it looked in Photoshop. Leave the [0] off and ImageMagick treats each layer as a separate image and exports them all, which is the classic surprise that sends people back to search.

bash
magick "design.psd[0]" design.png

No Photoshop required. ImageMagick reads PSD natively. On ImageMagick 7 the command is magick; on older 6.x installs it is convert (convert "design.psd[0]" design.png), and convert still works as a compatibility shim on 7. The quotes around the filename matter: the square brackets in design.psd[0] are glob characters in most shells, so quoting keeps the shell from mangling them.

Why the [0] matters

A PSD is not one image. It is a stack of layers, plus a pre-rendered flattened version of the whole thing that Photoshop bakes in when it saves. ImageMagick exposes each of those as an indexed frame, the same way it treats the frames of an animated GIF:

  • design.psd[0] is the merged composite: the artwork as you see it in Photoshop, every layer combined.
  • design.psd[1], design.psd[2], and up are the individual layers.

So magick design.psd design.png (no index) is really "export every frame," and ImageMagick obliges by writing design-0.png, design-1.png, design-2.png, one per layer. That is occasionally what you want, but if you searched for "PSD to PNG" you almost certainly wanted one flat image, and [0] is how you ask for it.

Extract a single layer, or every layer

The same index that gives you the composite gives you any individual layer. Want layer 2 on its own?

bash
magick "design.psd[2]" layer2.png

To deliberately export every layer to its own numbered PNG, point ImageMagick at the PSD with no index and use a %d placeholder in the output name:

bash
magick design.psd layer-%d.png

That writes layer-0.png (the composite), layer-1.png, layer-2.png, and so on. This is the same [index] selection trick that pulls the first frame out of an animated GIF, so if you have used magick "clip.gif[0]" first-frame.png before, you already know this pattern.

-flatten as the alternative

If you would rather have ImageMagick rebuild the composite from the layers itself instead of reading Photoshop's saved one, use -flatten:

bash
magick design.psd -flatten design.png

This merges all layers down onto the background and writes a single PNG. In practice [0] and -flatten land on the same result for most files, but they get there differently: [0] reads the composite Photoshop already saved, while -flatten composites the layers in ImageMagick. When a file has layer masks or unusual blend modes, the two can diverge, and the saved composite ([0]) is usually the more faithful match to what you saw in Photoshop. Reach for -flatten when [0] looks wrong or the composite is missing.

PNG keeps an alpha channel, so [0] preserves the composite's transparency as long as the PSD had it. If a stray background creeps in, force the canvas transparent with magick "design.psd[0]" -background none -alpha on design.png.

Batch a whole folder

To convert a directory of PSDs, loop over them and take the composite from each:

bash
for f in *.psd; do
  magick "${f}[0]" "${f%.psd}.png"
done

${f%.psd}.png strips the .psd extension and adds .png, so hero.psd becomes hero.png. For very large PSDs, cap memory with -limit if a batch run balloons, for example magick -limit memory 2GiB "${f}[0]" out.png.

The honest limitation: Maximize Compatibility

Here is the catch worth knowing before you trust a batch run. ImageMagick reads the saved composite for [0], and that composite is only guaranteed to be present and correct if the file was saved from Photoshop with Maximize Compatibility turned on (Photoshop's "Maximize PSD and PSB File Compatibility" preference). With it on, Photoshop writes that flattened preview into the file and [0] renders exactly what you designed.

With it off, the saved composite may be stale or missing, and a PSD that leans on adjustment layers, smart objects, or non-trivial blend modes can render wrong: washed-out color, missing effects, or a result that does not match Photoshop. ImageMagick reads the file rather than running Photoshop's rendering engine, so anything Photoshop computes at display time that was not baked into the saved composite will not be reproduced. There is no flag that fixes this; the fix is to re-save the PSD with Maximize Compatibility on. It is the single most common reason a command-line PSD conversion comes out looking off, and it is not an ImageMagick bug.

On macOS: sips reads PSD too

If you are on a Mac and would rather not install ImageMagick, the built-in sips (Scriptable Image Processing System) lists psd among its supported input formats and can write a PNG:

bash
sips -s format png design.psd --out design.png

sips reads Photoshop's saved composite the same way, so the Maximize Compatibility caveat above applies here as well. It has no layer-index concept, so it only ever gives you the flattened image, never individual layers. For anything beyond a quick one-off conversion, ImageMagick is the more capable tool, but sips is genuinely handy when it is already on the machine.

FAQ

Because you left the index off. A PSD contains a flattened composite plus every individual layer, and ImageMagick exports all of them by default. Use magick "design.psd[0]" design.png to select just the composite (the flattened artwork), which is the single image almost everyone wants.

[0] reads the flattened composite that Photoshop saved inside the file. -flatten tells ImageMagick to merge the layers itself. They usually match, but with layer masks or blend modes they can differ, and the saved composite is normally the more faithful one. Use -flatten only when [0] looks wrong.

The PSD was almost certainly saved without Photoshop's Maximize Compatibility option, so the flattened composite ImageMagick reads is stale or missing. Re-save the PSD from Photoshop with Maximize Compatibility turned on, then convert again. ImageMagick reads the file rather than rendering it the way Photoshop does, so anything not baked into the saved composite will not appear.

No. ImageMagick reads and writes PSD natively, and on macOS the built-in sips can also read PSD. Neither needs Photoshop. The only thing Photoshop affects is whether the file was saved with Maximize Compatibility, which determines how faithfully the composite renders.

Loop over them in the shell and take the composite from each: for f in *.psd; do magick "${f}[0]" "${f%.psd}.png"; done. That writes one PNG per PSD, keeping the original base name.

See also

Sources

Authoritative references this article was fact-checked against.

TagsImageMagickPSDPNGPhotoshopCLIimage conversionmagick

Found this useful? Pass it on.

Copied

Ishan Karunaratne

Software Systems Architect · Senior Software Engineer · Engineering Leadership

Software systems architect and senior software engineer with more than two decades designing, building, and running production software, Linux systems, and DevOps infrastructure, and lately working AI into the stack. Now a CTO, though what I write here is drawn from the full arc of that work, across architecture, engineering, and operations, not any single job.

Keep reading

Related posts