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
- Crop PSD Image with Shift Approach in Java
- Crop PSD Image with Rectangular Coordinates in Java
- Rotate PSD Image at any Angle 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> <id>AsposeJavaAPI</id> <name>Aspose Java API</name> <url>http://repository.aspose.com/repo/</url> </repository>
<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:
- Load the input PSD file into a RasterImage class object.
- Cache the image using cacheData method.
- Define shift values and pass them to the crop method.
- 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:
- Load an existing image into an instance of RasterImage class.
- Cache the image for better performance.
- Create an instance of Rectangle class with the desired size.
- 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:
- Load the source PSD image file with RasterImage class.
- Before rotation, the image should be cached for improved performance.
- Specify the angle for rotation in the rotate method.
- 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.
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.