Recently, we published a blog post that demonstrates how to change opacity, blending modes, and color overlays in Photoshop layers using Aspose.PSD for Python via .NET. However, this article will go through how to resize, rotate, and crop PSD layers in Python using this SDK. We will move one step further in PSD files automation with the help of the features offered by Aspose.PSD for Python via .NET. In addition, we will show you the output processed by this Python SDK. So, let’s start by installing this SDK and then we will jump right to the implementation.

Installation

If you have not alrealy installed Aspose.PSD for Python via .NET, you can install it by running the following command:

pip install aspose-psd

Otherwise, you may download this Python SDK from this link.

Resize, Rotate, & Crop PSD Layers in Python

You can opt for this programmatic solution to crop or flip a Photoshop layer. Please follow the steps stated below:

  • Create an object of the PngOptions class and set PNG save options with alpha channel.
  • Initialize an instance of the PsdLoadOptions class and set PSD load options.
  • Load the PSD image using the specified options.
  • Cast the loaded image to PsdImage type for layer access.
  • Save the original PSD (before any changes) as a PNG for comparison.
  • Invoke the resize method to resize layer at index 2 to 25x25 pixels using high-quality resampling.
  • Rotate layer at index 5 by 45 degrees clockwise with yellow background fill.
  • Increase contrast of layer at index 3 by a factor of 3.
  • Crop layer at index 10 to a rectangle starting at (10, 10) with size 20x20.
  • Call the save method to save the updated image after all layer modifications.

The following code sample shows how to resize, rotate, and crop PSD layers in Python: Output:

flip-photoshop-layers

Get a Free License

Get a free temporary license to try this SDK without evaluation limitations.

Summing up

Aspose.PSD for Python via .NET has made it quite easy and simple to resize, rotate, and crop PSD layers in Python programmatically. You have seen that we can resize, crop and flip Photoshop layers simply by calling methods. In fact, you can do much more as there is a huge stack of features provided by this Python SDK. So, stay in touch with the documentation and API References for new releases. Moreover, you can check out our GitHub examples in case of any ambiguity.

Lastly, please visit our forum to ask questions.

Explore