Create PSD or PSB Image From Scratch using Java

Contents
[ ]

Overview

To create a PSD or PSB file from scratch using Aspose.PSD for Java, follow these steps:

  • Import Necessary Classes: Import the required classes from the Aspose.PSD library.

  • Specify Output File Name and Path: Define the name and path for the output PSD or PSB file.

  • Create PSD Image: Instantiate a new PSD image with the desired dimensions.

  • Add Regular PSD Layer: Add a regular layer to the PSD image and update it using the graphic API.

  • Create Text Layer: Add a text layer to the PSD image with the desired text content and position.

  • Apply Effects: If desired, apply effects such as drop shadow to the text layer.

  • Save PSD File: Save the created PSD image to the specified output file.

  • Please note that the Aspose.PSD library must be installed and correctly configured in your Java environment for these steps to work. Refer to the official Aspose.PSD documentation for detailed installation and usage instructions.

Please check full example.

Example

public class CreateFileFromScratchExample {
public static void main(String[] args) {
String outputFile = "CreateFileFromScratchExample.psd";
// Create PSD Image with specified dimensions
try (PsdImage img = new PsdImage(500, 500)) {
// Create Regular PSD Layer and update it with Graphic API
Layer regularLayer = img.addRegularLayer();
// Use popular Graphic API for Editing
Graphics graphics = new Graphics(regularLayer);
Pen pen = new Pen(Color.getAliceBlue());
LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(250, 250, 150, 100),
Color.getRed(), Color.getAquamarine(), 45);
graphics.drawEllipse(pen, new Rectangle(100, 100, 200, 200));
graphics.fillEllipse(brush, new Rectangle(250, 250, 150, 100));
// Create Text Layer
TextLayer textLayer = img.addTextLayer("Sample Text", new Rectangle(200, 200, 100, 100));
// Adding Shadow to Text
DropShadowEffect dropShadowEffect = textLayer.getBlendingOptions().addDropShadow();
dropShadowEffect.setDistance(0);
dropShadowEffect.setSize(8);
dropShadowEffect.setColor(Color.getBlue());
// Save PSD File
img.save(outputFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}