Problem with PSD to PNG conversion (Opacity and Transparent Background)
Posted: 2016-09-12T17:30:17-07:00
Greetings,
When I use ImageMagick command-line tool to convert PSD to PNG. I have noticed a behavior which is strange and hard for me to understand. I will try my best to put factual information here.
What's in the PSD file?
I'm using Photoshop CC to construct PSD file. I have a transparent background and I have one visible shadow layer with R=0 G=0 B=0 and varying opacity values around shadow region. At the borders opacity values are 0% and as you move from borders to center region opacity value increase to ~30%.
ImageMagick command-line to convert to PNG:
(interested in Composite layer hence appended [0])
> convert.exe input.psd[0] output.png
Observations:
- The output PNG file doesn't retain the same RGB values. Though it retains Opacity values as input PSD file. For example, in PSD input file, if I have R=G=B=0 opacity= 29% at pixel [100x100] then output PNG file has R=195 G=195 B=195 Opacity=29%. These are not random numbers to me it represent remaining 71% of opacity value applied to the color channels. All pixels around shadow region has the same logic.
- I have used PhotoshopCC > SaveAs option and GIMP > Export feature to convert PSD to PNG file and it works perfectly fine - RGB values matches.
- When I compare PNGs saved by PhotoshopCC/GIMP vs ImageMagick output PNG. Shadow color changed from Black foreground to White foreground. So, if you have White background applied to PNG then you will notice that shadow is lighter and smaller. Otherwise with non-white background you will see White foreground in shadow region (same size).
- In that case I decided to debug my PSD reader code (no library used) and it looks like we were reading the same RGB values that we pass to generate PNG file.
Questions:
1. What is actually stored in PSD file? How to cross-examine pixel data?
2. Is it broken? How can I fix it?
(As a hack- I managed to convert all colorspace value back to 0 and it resembles the output produced by PhotoshopCC.)
I took a screenshot of input PSD file and output produced by PhotoshopCC and ImageMagick - https://drive.google.com/file/d/0B0eLSA ... sp=sharing
Let me know if you need more information in order to help me. I really appreciate your time!
Thanks & Regards,
Rahul Patel
When I use ImageMagick command-line tool to convert PSD to PNG. I have noticed a behavior which is strange and hard for me to understand. I will try my best to put factual information here.
What's in the PSD file?
I'm using Photoshop CC to construct PSD file. I have a transparent background and I have one visible shadow layer with R=0 G=0 B=0 and varying opacity values around shadow region. At the borders opacity values are 0% and as you move from borders to center region opacity value increase to ~30%.
ImageMagick command-line to convert to PNG:
(interested in Composite layer hence appended [0])
> convert.exe input.psd[0] output.png
Observations:
- The output PNG file doesn't retain the same RGB values. Though it retains Opacity values as input PSD file. For example, in PSD input file, if I have R=G=B=0 opacity= 29% at pixel [100x100] then output PNG file has R=195 G=195 B=195 Opacity=29%. These are not random numbers to me it represent remaining 71% of opacity value applied to the color channels. All pixels around shadow region has the same logic.
- I have used PhotoshopCC > SaveAs option and GIMP > Export feature to convert PSD to PNG file and it works perfectly fine - RGB values matches.
- When I compare PNGs saved by PhotoshopCC/GIMP vs ImageMagick output PNG. Shadow color changed from Black foreground to White foreground. So, if you have White background applied to PNG then you will notice that shadow is lighter and smaller. Otherwise with non-white background you will see White foreground in shadow region (same size).
- In that case I decided to debug my PSD reader code (no library used) and it looks like we were reading the same RGB values that we pass to generate PNG file.
Questions:
1. What is actually stored in PSD file? How to cross-examine pixel data?
2. Is it broken? How can I fix it?
(As a hack- I managed to convert all colorspace value back to 0 and it resembles the output produced by PhotoshopCC.)
I took a screenshot of input PSD file and output produced by PhotoshopCC and ImageMagick - https://drive.google.com/file/d/0B0eLSA ... sp=sharing
Let me know if you need more information in order to help me. I really appreciate your time!
Thanks & Regards,
Rahul Patel