Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Created August 5, 2025 12:12
Show Gist options
  • Save aspose-com-gists/320443f3985eb014661479ac8dd8d54f to your computer and use it in GitHub Desktop.
Save aspose-com-gists/320443f3985eb014661479ac8dd8d54f to your computer and use it in GitHub Desktop.
Create a PSB File in Python
# Import required modules from Aspose.PSD
import aspose.psd as psd
from aspose.psd import Graphics, Pen, Color, Rectangle
from aspose.psd.brushes import LinearGradientBrush
from aspose.psd.fileformats.psd import PsdImage
# Define the output file name
outputFile = "CreateFileFromScratchExample.psb"
# Create a new PSD image with 500x500 dimensions.
with PsdImage(500, 500) as img:
# Add a regular layer to the PSD image by calling the add_regular_layer method.
regularLayer = img.add_regular_layer()
# Create a Graphics object to draw on the regular layer.
graphics = Graphics(regularLayer)
# Create a pen with AliceBlue color for stroke (outline).
pen = Pen(Color.alice_blue)
# Create a linear gradient brush to fill shapes from red to aquamarine.
brush = LinearGradientBrush(Rectangle(250, 250, 150, 100), Color.red, Color.aquamarine, 45)
# Draw an ellipse (circle-like shape) using the pen.
graphics.draw_ellipse(pen, Rectangle(100, 100, 200, 200))
# Fill another ellipse with the gradient brush.
graphics.fill_ellipse(brush, Rectangle(250, 250, 150, 100))
# Add a text layer with the text "Sample Text" inside a rectangle area.
textLayer = img.add_text_layer("Sample Text", Rectangle(200, 200, 100, 100))
# Add a drop shadow effect to the text layer.
dropShadowEffect = textLayer.blending_options.add_drop_shadow()
dropShadowEffect.distance = 0 # Distance of shadow from text
dropShadowEffect.size = 8 # Blur size of the shadow
dropShadowEffect.color = Color.blue # Color of the shadow
# Call the save method to save the final image to the output file.
img.save(outputFile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment