Last active
December 16, 2020 16:31
-
-
Save aspose-com-gists/0761bcf61600e99dae1491621168dc1a to your computer and use it in GitHub Desktop.
Convert PSD to raster images in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load a PSD file as an image and caste it into PsdImage | |
PsdImage psdImage = (PsdImage) Image.load("sample.psd"); | |
// Create an instance of PngOptions class | |
PngOptions pngOptions = new PngOptions(); | |
pngOptions.setColorType(PngColorType.TruecolorWithAlpha); | |
// Loop through the list of layers | |
for (int i = 0; i < psdImage.getLayers().length; i++) { | |
// Convert and save the layer to PNG file format. | |
psdImage.getLayers()[i].save(String.format("layer_out{0}.png", i + 1), pngOptions); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load an existing PSD image as Image | |
Image image = Image.load("sample.psd"); | |
// Create an instance of PngOptions class | |
PngOptions pngOptions = new PngOptions(); | |
// Create an instance of BmpOptions class | |
BmpOptions bmpOptions = new BmpOptions(); | |
// Create an instance of GifOptions class | |
GifOptions gifOptions = new GifOptions(); | |
// Create an instance of JpegOptions class | |
JpegOptions jpegOptions = new JpegOptions(); | |
// Create an instance of Jpeg2000Options class | |
Jpeg2000Options jpeg2000Options = new Jpeg2000Options(); | |
// Call the save method, provide output path and export options to convert PSD file to various raster file formats. | |
image.save("psd-to-png.png", pngOptions); | |
image.save("psd-to-bmp.bmp", bmpOptions); | |
image.save("psd-to-gif.gif", gifOptions); | |
image.save("psd-to-jpg.jpeg", jpegOptions); | |
image.save("psd-to-jp2.jp2", jpeg2000Options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load image | |
Image img = Image.load("sample.psd"); | |
// Create PDF options | |
PdfOptions options = new PdfOptions(); | |
// Convert PSD to PDF | |
img.save("psd-to-pdf.pdf", options ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment