Crop or Rotate PSD Image in Java

Crop Resize PSD

PSD image files are used to design pictures for logos, banners, brochures, and many other purposes. In certain scenarios, you may need to crop or rotate a PSD file within your Java applications. This article covers how to crop or rotate a PSD file programmatically in Java.

Rotate or Crop a PSD File – Java API Installation

Aspose.PSD for Java API supports working with the PSD and several other Photoshop file formats. You can configure the API by downloading the JAR file from the New Releases, or using the following Maven configurations in your project:

Repository

<repository>
    <id>AsposeJavaAPI</id>
    <name>Aspose Java API</name>
    <url>http://repository.aspose.com/repo/</url>
</repository>

Dependency

<dependency>
     <groupId>com.aspose</groupId>
     <artifactId>aspose-psd</artifactId>
     <version>21.7</version>
     <classifier>jdk16</classifier>
</dependency>

Crop PSD Image with Shift Approach in Java

You can crop a PSD image by shifting the contents as per your requirements. Please follow the steps below for cropping the image by shifting contents:

  1. Load the input PSD file into a RasterImage class object.
  2. Cache the image using cacheData method.
  3. Define shift values and pass them to the crop method.
  4. Save output cropped image.

The following code shows how to crop a PSD image by shifting content programmatically in Java:

Crop PSD Image with Rectangular Coordinates in Java

You can crop any rectangular region in a PSD image by specifying the coordinates. You need to follow the below steps to crop a PSD image:

  1. Load an existing image into an instance of RasterImage class.
  2. Cache the image for better performance.
  3. Create an instance of Rectangle class with the desired size.
  4. Crop the image using the crop method and save output file.

The code snippet below demonstrates how to crop a PSD file with rectangular coordinates in Java:

Rotate PSD Image at any Angle in Java

In some situations, you might need to rotate the PSD images at a specific angle. Please follow the steps below for rotating a PSD image:

  1. Load the source PSD image file with RasterImage class.
  2. Before rotation, the image should be cached for improved performance.
  3. Specify the angle for rotation in the rotate method.
  4. Save the output file.

The below code sample explains how to rotate a PSD image in Java:

Get Free Evaluation License

You may request a free temporary license to evaluate the API without any limitations.

Conclusion

In this article, you have learned different approaches to crop a PSD image or rotate it at a specific angle. The API offers several other features to work with PSD and other supported file formats. Moreover, please take a look at the API Documentation for more information. Feel free to contact us at the Free Support Forum for any of your inquiries.

See Also

Convert PSD to TIFF Image Programmatically with Java