Magick::writeImages() creating unstable Photoshop PSD

Post any defects you find in the released or beta versions of the ImageMagick software here. Include the ImageMagick version, OS, and any command-line required to reproduce the problem. Got a patch for a bug? Post it here.
valen
Posts: 19
Joined: 2017-05-10T14:32:37-07:00
Authentication code: 1151

Magick::writeImages() creating unstable Photoshop PSD

Post by valen » 2017-06-06T12:39:18-07:00

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

I have a similar post in the developer forum, but am leaning more towards the possibility that this is a bug.

I am creating a std::list<Magick::Image> of images. Then I use Magick::writeImages() to build a Photoshop file, for example:

Magick::writeImages(myList.begin(), myList.end(), "c:\\temp\\myPsdFile.psd", true);

The first layer in my list is made by calling Magick::flattenLayers() on all the other layers so that my first layer is the composited version of all the actual layers.

When I open the PSD in Photoshop, all the layers are locked background layers, if you know what I mean. This is bad - Photoshop only allows 1 background layer. If I start to try and convert them to regular layers, I will get messages saying that Photoshop encountered a program error. I assume this is stemming from the fact that this PSD is invalid.
Last edited by valen on 2017-06-06T14:12:36-07:00, edited 1 time in total.

Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by Bonzo » 2017-06-06T14:03:02-07:00

I seem to remember fmw42 posting something about the first layer needing to be a flattened layer of all the other layers otherwise it would cause a problem with the psd file.
When reading a psd file into imagemagick this is what you find - psd[0] is a layer/file containing all the other layers

valen
Posts: 19
Joined: 2017-05-10T14:32:37-07:00
Authentication code: 1151

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by valen » 2017-06-06T14:11:19-07:00

I was thinking that the first layer *should* be the flattened layer, but really what does it matter? As long as there is a first layer, followed by more layers.
Otherwise, how do we confidently create this first layer? How is it composited?

But yes, I should have mentioned in my original post that I am creating my first layer by using Magick::flattenImages() on all the other layers. So, my first layer is "flattened".

I have clarified my original message to say that I am creating the flattened first layer.

snibgo
Posts: 12157
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by snibgo » 2017-06-06T14:13:18-07:00

I don't use Photoshop so can't help.

For people who do use PS, I suggest you paste a complete but minimal program and any required (small) input files (EDIT and the output PSD file) that demonstrate the problem.
snibgo's IM pages: im.snibgo.com

valen
Posts: 19
Joined: 2017-05-10T14:32:37-07:00
Authentication code: 1151

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by valen » 2017-06-06T15:02:42-07:00

I don't see how I can add attachments here. Well, here is an example program. It will take 3 existing JPEG images, and combine them into one 3 layer PSD file.

Note that I have recently discovered that the PSD appears to open up OK into Photoshop CC 2017, but not Photoshop CS6. I'm guessing that CC 2017 must have some error fixing going on that CS6 does not.

Code: Select all

using namespace Magick;

int main(int argc, char ** argv)
{
	InitializeMagick(*argv);

	try
	{
		std::string basePath = "c:\\temp\\";
		std::string layer1 = basePath + "layer1.jpg";
		std::string layer2 = basePath + "layer2.jpg";
		std::string layer3 = basePath + "layer3.jpg";

		Magick::Image image1(layer1);
		Magick::Image image2(layer2);
		Magick::Image image3(layer3);

		std::list<Magick::Image> layersToFlatten;
		layersToFlatten.push_back(image1);
		layersToFlatten.push_back(image2);
		layersToFlatten.push_back(image3);

		Magick::Image flattened;
		Magick::flattenImages(&flattened, layersToFlatten.begin(), layersToFlatten.end());

		std::list<Magick::Image> layersForPsd;
		layersForPsd.push_back(flattened);
		layersForPsd.push_back(image1);
		layersForPsd.push_back(image2);
		layersForPsd.push_back(image3);

		std::string outFile = basePath + "output.psd";
		Magick::writeImages(layersForPsd.begin(), layersForPsd.end(), outFile, true);
	}
	catch (std::exception &error_)
	{
		return 1;
	}

	return 0;
}

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by fmw42 » 2017-06-06T15:15:32-07:00

If you want to post some other files, you must post them to some free hosting service and put the URLs here

valen
Posts: 19
Joined: 2017-05-10T14:32:37-07:00
Authentication code: 1151

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by valen » 2017-06-07T07:04:22-07:00

Oh, ok. Unfortunately I am unable to do that at my job. But the code example I gave above should be enough for someone with Magick++ and Photoshop experience to test out and confirm.

User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by dlemstra » 2017-06-08T03:29:45-07:00

What happens when you strip the layers? Might be that some of the files contain metadata that makes it a background layer. You should really add your files here so we can test what happens with your files. Feel free to contact me with a PM so you can only email me links to your files.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

valen
Posts: 19
Joined: 2017-05-10T14:32:37-07:00
Authentication code: 1151

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by valen » 2017-06-08T07:00:35-07:00

What do you mean by "strip" the layers?

The process is pretty simple to test. I could attach files, but it would be almost just as easy to create the images on your end and test them.

Just create 2 or 3 JPG images. Then build an executable that runs code like in my original code sample. Then open the outputted PSD in Photoshop CS6 or earlier and see the problem.

Otherwise, what files would you like? I will send you a PM.

User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by dlemstra » 2017-06-14T22:26:43-07:00

Can you reproduce the issue with the 'logo:' image? In other words:

Code: Select all

std::string layer1 = "logo:";
I don't own Photoshop CS6 so I cannot test what fails and I was hoping it had something to do with your images. Please test this with the logo: image on all layers and let me know if it still fails.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

valen
Posts: 19
Joined: 2017-05-10T14:32:37-07:00
Authentication code: 1151

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by valen » 2017-06-15T07:04:01-07:00

By "logo:" are you referring to this image?

http://www.imagemagick.org/image/logo.jpg

I tested my code sample above with that image and I got the same results. It gave me a 3 layer Photoshop PSD file and each layer is locked like a background layer. If I try to unlock them (convert them into non-background layers) the first one usually works, but the next one Photoshop says "Could not complete your request because of a program error." The file is unstable.

User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by dlemstra » 2017-06-15T11:05:51-07:00

Is it possible for you to create a PSD file that uses the logo: (you can use this as a filename, its a build-in format) with CS6 and share it here? And also share the file that you created with Magick++? Then we might be able to figure out the difference between those two files.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by fmw42 » 2017-06-15T11:12:56-07:00

dlemstra wrote:
2017-06-15T11:05:51-07:00
Is it possible for you to create a PSD file that uses the logo: (you can use this as a filename, its a build-in format) with CS6 and share it here? And also share the file that you created with Magick++? Then we might be able to figure out the difference between those two files.
I do not think PS can read IM internal image formats with colon added to the end of the filename. It probably should be converted to a suffixed file. Identify says logo: is a GIF format. So perhaps

Code: Select all

convert logo: logo.gif
Then import logo.gif into PS.

User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by dlemstra » 2017-06-15T11:24:27-07:00

Sorry reading my message back it seems I switched the order. Thanks for your remark Fred. Just wanted to tell @valen that 'logo:' could be used as the file name in Magick++.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate

valen
Posts: 19
Joined: 2017-05-10T14:32:37-07:00
Authentication code: 1151

Re: Magick::writeImages() creating unstable Photoshop PSD

Post by valen » 2017-06-15T14:13:06-07:00

I have some PSD files you can test. Can you IM me with your email and I will send them as attachments...

Post Reply