Setting layer position in PSD

Hi,

I am currently evaluating Aspose PSD for Java . What I am trying to do is I have created a template PSD and a layer now, I want to add the layer to the psd with location. Is this possible?

Thanks!

@Kerrah

Can you please share the details of requirements on your end and possibly a sample file exhibiting your requirements.

My current code shows below:

PsdImage image = new PsdImage(width, height);
Graphics graphic = new Graphics(image);
graphic.clear(Color.getYellow());

File imageFile = new File(dataDir);
InputStream inputStream = new FileInputStream(imageFile);
Layer layer1 = new Layer(inputStream);
image.addLayer(layer1);
image.save(outPsdFilePath);

But I want to locate the layer with left=245px and top=50px
in the image, which shows as the psd file attached.output.zip (5.2 KB)

@Kerrah

Can you please try following properties.

            Layer2.setLeft(675);
            Layer2.setTop(0);

It shows as this file.output.zip (2.9 KB)

@Kerrah

Can you please share the source file and desired output file along with used code. I will try to create a sample code for you to help you out.

The source file is logo.png (5.1 KB), and I want to have an output like this output.zip (5.2 KB).
Now I’m using code without locating the logo.

PsdImage image = new PsdImage(width, height);
Graphics graphic = new Graphics(image);
graphic.clear(Color.getYellow());

File imageFile = new File(dataDir);
InputStream inputStream = new FileInputStream(imageFile);
Layer layer1 = new Layer(inputStream);
layer1.resize(30, 50);
image.addLayer(layer1);
image.save(outPsdFilePath);

@Kerrah

Please try using the following sample code on your end.

    public static void TestPSDLayerPosition() throws FileNotFoundException
    {
        PsdImage image = new PsdImage(2000, 2000);
        Graphics graphic = new Graphics(image);
        graphic.clear(com.aspose.psd.Color.getYellow());

        String path = "//Users//mudassirkhan//Downloads//";
        //              File imageFile = new File(dataDir);
        File imageFile = new File(path+"logo.png");
        InputStream inputStream = new FileInputStream(imageFile);

        Layer Layer2 = new Layer(inputStream);

        Layer2.setResources(new LayerResource[] { });
        Layer2.resize(image.getWidth()/3, image.getHeight()/3);

        int width = Layer2.getWidth();
        int height = Layer2.getHeight();

        Layer2.setLeft(800);
        Layer2.setTop(0);

        Layer2.setRight(Layer2.getLeft() + width);
        Layer2.setBottom(Layer2.getTop() + height);

        image.addLayer(Layer2);
        image.save(path+"Saved.psd");
    }

My problem solved. Thanks a lot! :laughing:

@Kerrah

Great to know :slight_smile: .