Hello - I'm using ImageMagick 6.5.9.
I've created a photoshop file using the following method:
1) Create a photoshop file
2) Select "new layer from background" so you have a 1 layer file
3) Fill the background with red using the paint bucket tool
4) Set the layer opacity to something other than 100% (i.e. 25%).
I'm trying to push this file through ImageMagick++ and I can't get anything useful out of layers that have opacity in them. I've simplified the code down to the following:
Magick::InitializeMagick(NULL);
std::vector<Image> images;
readImages( &images, "test.psd" );
images[0].write("test0.png");
images[1].write("test1.png");
The first save of the entire image, test0, looks correct. But the second save of just the one layer, test1, comes out completely transparent.
Note that when the opacity of the layer is 100%, both saves look correct.
If I call images[1].pixelColor(5,5), I get a color of type RGBA, but a pixel opacity of 65535, which is transparent. So somewhere along the way the pixel is getting set to transparent instead of solid, and any opacity setting has been lost?
Any ideas on how to work around this issue (note: The issue is not because there is only 1 layer in the file, when I have many layers in the file, the problem still happens, I'm just trying to make the example as simple as possible).
Thanks.
opacity in psd files not working correctly in magick++?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: opacity in psd files not working correctly in magick++?
I know very little about psd files. But the first layer [0] will be the flattened or composite file.
I tried to recreate your exampe (slightly different method in PS). I don't know if I did it correctly as I hardly use PS and only have PS CS.
Identify -verbose shows two layers, the first is r=1, g=0.5, b=0.5, a=0.5 (strange about the g and b). The second is r=1, g=0, b=0, a=0 (totally transparent)
converting to png (convert image.psd image.png) results in two files, -0 and -1 which identify -verbose shows the same info.
Photoshop layers and IM layers may not convert to meaningful images for IM. Most people just use layer [0] to get the flattened image.
I tried to recreate your exampe (slightly different method in PS). I don't know if I did it correctly as I hardly use PS and only have PS CS.
Identify -verbose shows two layers, the first is r=1, g=0.5, b=0.5, a=0.5 (strange about the g and b). The second is r=1, g=0, b=0, a=0 (totally transparent)
converting to png (convert image.psd image.png) results in two files, -0 and -1 which identify -verbose shows the same info.
Photoshop layers and IM layers may not convert to meaningful images for IM. Most people just use layer [0] to get the flattened image.
Re: opacity in psd files not working correctly in magick++?
Hmmm... well let me describe what I'm trying to do here. I can't use image[0] - the composited image - in what I'm trying to accomplish.
I have a psd file with many layers (30-50). Some of them have the opacity set inside of Photoshop. I need to save out each individual layer as a separate png, and I need to preserve that opacity setting.
I don't really care if the image comes out with the opacity setting applied, or if it comes out at 100% opacity but I can extract the opacity setting later as a text value or something.
Any ideas?
I have a psd file with many layers (30-50). Some of them have the opacity set inside of Photoshop. I need to save out each individual layer as a separate png, and I need to preserve that opacity setting.
I don't really care if the image comes out with the opacity setting applied, or if it comes out at 100% opacity but I can extract the opacity setting later as a text value or something.
Any ideas?
- fmw42
- Posts: 25562
- Joined: 2007-07-02T17:14:51-07:00
- Authentication code: 1152
- Location: Sunnyvale, California, USA
Re: opacity in psd files not working correctly in magick++?
sorry, i really cannot help further as I don't know that much about PSD files and their layers.
Re: opacity in psd files not working correctly in magick++?
Ok, I think I've found a bug in the source code in psd.c.
In the part where it says:
/*
Correct for opacity level.
*/
I think the math is wrong where it multiplies the opacity. I'm looking into how to fix it.
In the part where it says:
/*
Correct for opacity level.
*/
I think the math is wrong where it multiplies the opacity. I'm looking into how to fix it.