Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the layers from a PSD file?

Tags:

c#

.net

photoshop

I want to retrieve all layers from a PSD file and get their name, X and Y position.

Is there a C# Lib that can do that?

I've tried this lib from CodeProject, but I always get TargetInvokeException. My PSD files are from Photoshop CS5...


Exploring Paint.NET as Robin suggested I could get to this code:

var ps = new PsdFile();
ps.Load(file);
var name = ps.Layers[0].Name;
var xy = ps.Layers[0].Location;

I needed to include these references:

  • PhotoShop.dll
  • PaintDotNet.Core.dll
like image 518
BrunoLM Avatar asked Dec 04 '10 02:12

BrunoLM


2 Answers

You could use the PSD-plugin for Paint.NET to do it.

Should be fairly easy to extract the parser library from there.

http://psdplugin.codeplex.com/

like image 92
Robin Orheden Avatar answered Nov 07 '22 22:11

Robin Orheden


0xA3 gives an answer in this thread. I've not personally used this library, but it seems like it is pretty simple and works well.

\Direct Copy\

The ImageMagick libraries (which provide bindings for C#) also support the PSD format. They might be easier to get started with than getting into the Paint.NET code and also come with a quite free (BSD-like) license.

A simple sample (found at http://midimick.com/magicknet/magickDoc.html) using MagickNet would look like this:

using System;

static void Main(string[] args)
{
    MagickNet.Magick.Init();
    MagicNet.Image img = new MagicNet.Image("file.psd");
    img.Resize(System.Drawing.Size(100,100));
    img.Write("newFile.png");
    MagickNet.Magick.Term();
}

Note: MagickNet has moved to http://www.codeproject.com/KB/dotnet/ImageMagick_in_VBNET.aspx

like image 24
Sprunth Avatar answered Nov 07 '22 23:11

Sprunth