PSD-parser

Photoshop with its PSD files is a standart de-facto. The game wants to read all that additional parameters, like pivot point, slices and so on. We decided to use separate layers to store this info. Then is came to a need of PSD-parser. We did’t found any real quality parsers, so we made it by ourselves in a week.

Here is an example of using this neat thing:

PSDParser parser = new PSDParser(new FileInputStream("image.psd")); 
PSDLayerAndMask layerAndMask = parser.getLayerAndMask();    
 
List layers = layerAndMask.getLayers(); 
List images = layerAndMask.getImageLayers(); 
int i = 0; 
for (PSDLayerStructure layer : layers) { 
    PSDLayerPixelData pixelData = images.get(i); 
    BufferedImage image = pixelData.getImage(); 
    if (image != null) 
	ImageIO.write(image, "png", new File(layer.getName() + ".png")); 
	    i++; 
}

Sourse

Sourse can be downloaded freely under APACHE LICENSE.
Features: all layers export (incl. main), main file info, full slices support.
Use this on your own risc, and we’ll be glad to hear any comments too (bugs, ideas).

psd_parser.7z

21 thoughts on “PSD-parser

  1. I was looking for a real FREE-OF-CHARGE PSD parser and finally I found it ! This is such a BIG gift which you guys ever created. This would save me and others from reinvent the wheel.

    I was using the ImageRO to deal with the PSD parser but it’s messages bout something like “liences”,”expired”… made me sick. I was intend to read and write my own parser but bad news is that I had no documents bout the PSD at all… Thank and double, triple thanks you again, you guys lightened up my cruel, miserable life. Keep up the good works, hope you all the best.

  2. Thanks for the info Mikhail.

    On another note, this is pretty cool. How can I apply layer effects to the parsed layer image? I see how the image is extracted in the Image Resource Blocks, however I can’t figure out how I could apply an effects layer to an image resource block. For example, create a text layer in a psd file and then apply a drop shadow effect to the text layer. The image that gets parsed out has the text, however, the drop shadow is not in the image itself. How can I apply the drop shadow to the image in the resource block? Any help is appreciated guys.

    SkyPainter

  3. It seems like the only way is to merge (or rasterize, I’m not quite familiar with Photoshop) an effect with the layer. This parser is very simple, it just extracts layers from a psd-file.

  4. Error by loading large PSD file (10 Mb):

    Exception in thread “main” java.lang.ArrayIndexOutOfBoundsException: 786
    at com.alternativagame.resource.utils.psd.images.unpacker.RLEPackBits.unpack(RLEPackBits.java:45)
    at com.alternativagame.resource.utils.psd.images.RLEParser.(RLEParser.java:49)
    at com.alternativagame.resource.utils.psd.layer.PSDLayerPixelData.(PSDLayerPixelData.java:44)
    at com.alternativagame.resource.utils.psd.section.PSDLayerAndMask.parseLayerInfo(PSDLayerAndMask.java:65)
    at com.alternativagame.resource.utils.psd.section.PSDLayerAndMask.(PSDLayerAndMask.java:34)
    at com.alternativagame.resource.utils.psd.PSDParser.(PSDParser.java:40)

  5. Excellent, thanks. BTW, I did get an error when parsing a 4-character layer name and fixed it by changing

    length = (length % 2) == 0 ? 1 : length;

    to

    length += 1 – length % 2;

    in the PSDImageResources constructor.

  6. Exception in thread “main” java.lang.OutOfMemoryError: Java heap space
    at types.VString.(VString.java:26)

    Just as soon as I load a file with 2 layers. Only 1.04 mb

    Thanks

  7. I think you should create a project on some free project hosting service. I’m sure there is developers who would like to participate in PSD reader development. Sorry for my bad english :)

  8. I have given a task to read psd file made from photoshop cs5 from c# programming language. I had read psd file by using file format specification up to layer listings.
    But now I am stucked on reading fonts on that file. After googling, I had found psd parser which reads font information for photoshop 5.0 only. But my file is on photoshop 6.0.

    Please suggest me how to read font list or font details used on layers via c#? Also in which key or location font information is stored on psd binary file?

    Any help is heartly wellcome.

    Regards,
    Biran

  9. That’s a great job, I really find this very interesting.
    As far as I understood, this is only a Parser?
    Is there a way to modify or create a PSD file?
    For instance, how can I add a Channel?

    Thanks a lot,
    LeoBen

  10. >> As far as I understood, this is only a Parser?
    Yes, it’s only parser

    >> Is there a way to modify or create a PSD file?
    >> For instance, how can I add a Channel?
    No, it can’t write data

  11. @Alexey Kviring Hi, how can i get all the layer names the psd contains..I have a psd file which has layers like name, phone, mobile, email etc. How do I get the list of layers and its names. Will the below code work?

    PSDParser parser = new PSDParser(new FileInputStream(Sample01.psd"));
    PSDLayerAndMask layerAndMask = parser.getLayerAndMask();

    List layers = layerAndMask.getLayers();
    List images = layerAndMask.getImageLayers();
    int i = 0;
    for (PSDLayerStructure layer : layers) {
    System.out.println("layer names"+layer.getName());
    }

    Thanks for the Parser library.

  12. The code which i posted is not working, It throws a Java heap space error. I have restarted my system. Is this a Bug or Am I missing something..


    HTTP ERROR 500

    Problem accessing /upload/uploadPsd. Reason:

    Java heap space

    Caused by:

    java.lang.OutOfMemoryError: Java heap space
    at com.alternativagame.resource.utils.psd.types.VString.(VString.java:26)
    at com.alternativagame.resource.utils.psd.irb.Slice.(Slice.java:84)
    at com.alternativagame.resource.utils.psd.irb.SlicesIRB.(SlicesIRB.java:34)
    at com.alternativagame.resource.utils.psd.section.PSDImageResources.makeIRB(PSDImageResources.java:78)
    at com.alternativagame.resource.utils.psd.section.PSDImageResources.(PSDImageResources.java:53)
    at com.alternativagame.resource.utils.psd.PSDParser.(PSDParser.java:38)

Leave a Reply