Reputation: 18035
Is there a library in C# that will allow me to read the layers in a photoshop file (PSD) and extract them as transparent images (PNG)?
Photoshop has a batch command that will extract all layers in individual files but there is no choice of transparent PNGs. My goal is to create a small utility program that will create combinations of layers as you like (for example think of creating a card deck).
Upvotes: 6
Views: 14353
Reputation: 11592
I found a code sample that does this in Java.
"Supports uncompressed or RLE-compressed RGB files only"
Also supports only older PSD versions :
"Does not support additional features in PS versions higher than 3.0"
Also ImageMagick handles PSD and has interfaces to many languages :
"Choose from these interfaces: G2F (Ada), MagickCore (C), MagickWand (C), ChMagick (Ch), ImageMagickObject (COM+), Magick++ (C++), JMagick (Java), L-Magick (Lisp), NMagick (Neko/Haxe), MagickNet (.NET), PascalMagick (Pascal), PerlMagick (Perl), MagickWand for PHP (PHP), IMagick (PHP), PythonMagick (Python), RMagick (Ruby), or TclMagick (Tcl/TK)"
Upvotes: 1
Reputation: 99
I couldnt find much on this anywhere, but this is how i ended up doing it.
using Photoshop;
Photoshop.PsdFile psd = new Photoshop.PsdFile();
psd.Load(pingTextsPsd);
for (int j = 0; j < psd.Layers.Count; j++)
{
System.Drawing.Image myPsdImage = ImageDecoder.DecodeImage(psd.Layers[j]);
myPsdImage.Save(pingsOutputPath + psd.Layers[j].Name + ".png");
}
i had to downloaded the cs files that Mr Frank Blumenberg did (based on the Endogine engine by Jonas Beckeman), as getting the paintdotnet dll itself wasnt enough.
I believe it was here that i got the cs files.
http://code.google.com/p/skimpt/source/browse/trunk/Skimpt3/Skimpt3/classes/photoshop/?r=72
This should allow you to get the layers..
:-)
This seems to work fine with CS6 files too.
update: a vs2013 website is here: http://goo.gl/H6nWSN.
Upvotes: 4
Reputation: 13933
ImagicMagick (which was mentioned in the other SO article) does allow layers to be extracted separately. See: http://www.rubblewebs.co.uk/imagemagick/psd.php
You can try this for yourself using the command line tool:
convert boots.psd[0] -thumbnail 340x340 boots_png.png
Upvotes: 1
Reputation: 2894
If you don't have Photoshop installed, then you may want to look at the code at http://frankblumenberg.de/doku/doku.php?id=paintnet:psdplugin for more sample code that loads PSD files.
Unfortunately, I don't know of a pre-existing PNG library that does what you want but the canonical library code for PNG file manipulation is located at http://www.libpng.org/pub/png/.
Upvotes: 0
Reputation: 1038930
There's a nice article on CodeProject which might be helpful. And here's a thread on SO discussing PSD file format parsing with C#.
Upvotes: 4