How to write multi-layer Photoshop PSD file?

Questions and postings pertaining to the development of ImageMagick, feature enhancements, and ImageMagick internals. ImageMagick source code and algorithms are discussed here. Usage questions which are too arcane for the normal user list should also be posted here.
Post Reply
valen
Posts: 19
Joined: 2017-05-10T14:32:37-07:00
Authentication code: 1151

How to write multi-layer Photoshop PSD file?

Post by valen »

ImageMagick++ (7.0.5-7-Q8-x64-dll)
Visual Studio 2015
Windows 10
Adobe Photoshop CS6 & CC 2017

I am reading in a custom formatted image that contains multiple image layers. I can create a Magick::Image object for each layer, and I can call Magick::Image::Write() on each Image object to write out a PSD file. But these PSD files only have one layer, obviously.

I want to be able to collect a bunch of Magick::Image objects and write out 1 PSD file with all those Images as separate layers within.

How can I do this with Magick++? I'm having trouble finding any help on this.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to write multi-layer Photoshop PSD file?

Post by snibgo »

For writing multiple images into a single file in Magick++, see http://www.imagemagick.org/Magick++/STL.html
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to write multi-layer Photoshop PSD file?

Post by fmw42 »

Be sure you create a flattened layer for the first layer, plus all your separate layers and write them all to PSD. PSD from ImageMagick must have the flattened layer first.
valen
Posts: 19
Joined: 2017-05-10T14:32:37-07:00
Authentication code: 1151

Re: How to write multi-layer Photoshop PSD file?

Post by valen »

Thanks. I am now able to create a std::list<Magick::Image> of images. Then I use Magick::writeImages() to create the Photoshop file. But now when I open the PSD in Photoshop, all the layers are locked as a background layer, if you know what I mean. So, for example if I have 5 images that I'm creating 1 PSD out of, the PSD will end up with 5 layers and each of those layers is a "background" layer instead of a regular layer. Is there some special property I'm supposed to set on the individual Magick::Image objects before I call Magick::writeImages() on them?
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: How to write multi-layer Photoshop PSD file?

Post by snibgo »

I don't use Photoshop, and don't know the difference between a background layer and regular layer. Sorry.
snibgo's IM pages: im.snibgo.com
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: How to write multi-layer Photoshop PSD file?

Post by fmw42 »

What was your exact command line(s)?

You have to create the flattened layer and save it and then use that and your original layers.

Code: Select all

magick layer1 layer2 ... layer5 -background none -flatten flataenedlayer
magick flattenedlayer layer1 layer2 ... layer5 result.psd
or

Code: Select all

magick layer1 layer2 ... layer5 ( -clone 0--1 -background none -flatten ) +insert result.psd
valen
Posts: 19
Joined: 2017-05-10T14:32:37-07:00
Authentication code: 1151

Re: How to write multi-layer Photoshop PSD file?

Post by valen »

I am not using a command line to do this. I am using the Magick++ API. I am creating a bunch of Magick::Image objects and then writing them to a PSD. The first image in the list of images is considered my "flattened" layer. The following images are the subsequent layers.

@snibgo
In Photoshop, when you start a new document you get a locked "background" layer to start with. You cannot edit the background layer. There can only be 1 background layer. You have the option to unlock and convert the background layer into a regular editable layer if you choose. There are not supposed to be multiple background layers, like ImageMagick is giving me when I run the Magick::writeImages() function. Magick::writeImages() is creating an unstable Photoshop document by creating multiple background layers. I hope I'm just doing something wrong in my process and someone here can correct me... Surely I'm not the first person to use Magick++ to create a multi-layer PSD.
jb123
Posts: 4
Joined: 2018-11-02T16:08:20-07:00
Authentication code: 1152

Re: How to write multi-layer Photoshop PSD file?

Post by jb123 »

Hi, did you ever solve the "all background layers" issue?
I still run into it with Magick.NET
Post Reply