Hello,
I’m using PNG images that are being rendered and I would like to have an option to save them in to the PSD format. I had trouble finding a way to do it properly in the documentation. Maybe I’m blind, but could somebody please point me in the right direction?
Thank you.
Best,
David
Edit: Forgot to mention, I’m using JAVA
@dqpowered
Please check the following article Creating, Opening and Saving Images|Documentation
Also, here is Java Version
public class Main {
public static void main(String[] args) {
openAsLayer("");
}
public static void openAsLayer (String dataDir) {
String outputFilePath = dataDir + "PsdResult.psd";
String[] filesList = new String[]{
"PsdExample.psd",
"BmpExample.bmp",
"GifExample.gif",
"Jpeg2000Example.jpf",
"JpegExample.jpg",
"PngExample.png",
"TiffExample.tif",
};
try (PsdImage image = new PsdImage(200, 200)) {
for (String s : filesList) {
String filePath = dataDir + s;
try (InputStream stream = new FileStream(filePath, FileMode.Open).toInputStream()) {
Layer layer = null;
try {
layer = new Layer(stream);
image.addLayer(layer);
} catch (Exception e) {
if (layer != null) {
layer.dispose();
}
throw e;
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
image.save(outputFilePath);
}
}
}
Aspose.PSD can not open files as Png, Jpeg or any other formats, but it can easily open these types of images as layer. And then the PSD file can be saved.
Thanks, this helped a lot!
One more, maybe a stupid question.
I came across Aspose.Imaging and I was wondering, do I have to always open the image file from directory or can I somehow convert it from a variable, for example a buffered image?
@dqpowered you can try to load whole file to the byte array and then use it for the stream. So, there are 2 options:
- Load from file
- Load from stream
If you did it differently by other product, please provide the code snippet. Possible we will add new cases for doing this.
Got it working with your help, so thank you once again.
I’m using “our” own node concept of visual coding which has a final render node that gets input from all the nodes that connect to it. That could be for example color, background color or custom layer (single image, image grid, random distribution grid, etc.) With using your help I managed to export all the separate layers in one PSD file and open it in Photoshop. There are still some small bugs, but that’s something I can fix in a few minutes.
Thank you!
1 Like