Skip to content

Instantly share code, notes, and snippets.

@aspose-com-gists
Last active October 15, 2025 17:54
Show Gist options
  • Save aspose-com-gists/00c5bd9eeedb5ac08a20d5499a8cdf3f to your computer and use it in GitHub Desktop.
Save aspose-com-gists/00c5bd9eeedb5ac08a20d5499a8cdf3f to your computer and use it in GitHub Desktop.
Apply Photoshop Layer Effects in Python
import aspose.psd as psd
from aspose.psd import Image, Color
from aspose.psd.fileformats.png import PngColorType
from aspose.psd.fileformats.psd import PsdImage
from aspose.psd.fileformats.psd.layers.fillsettings import GradientColorPoint, GradientTransparencyPoint, FillType, \
GradientFillSettings, PatternFillSettings, ColorFillSettings
from aspose.psd.imageloadoptions import PsdLoadOptions
from aspose.psd.imageoptions import PngOptions
from aspose.pycore import cast
# Apply Aspose.PSD license and load the source file.
license = psd.License()
license.set_license("atest.lic")
source = "nines.psd"
# Set the PNG options by creating an instance of the PngOptions class.
png_opt = PngOptions()
png_opt.color_type = PngColorType.TRUECOLOR_WITH_ALPHA
# Set the PSD load options by creating an object of the PsdLoadOptions class.
psd_opt = PsdLoadOptions()
psd_opt.load_effects_resource = True
# Load the PSD image by calling the load method.
with Image.load(source, psd_opt) as img:
# Cast to PsdImage
image = cast(PsdImage, img)
# Test data for gradient
gradient_color_points = [
GradientColorPoint(Color.red, 0, 50),
GradientColorPoint(Color.green, 1024, 50),
GradientColorPoint(Color.blue, 2048, 50)
]
tp1 = GradientTransparencyPoint()
tp1.location = 0
tp1.median_point_location = 50
tp1.opacity = 128
tp2 = GradientTransparencyPoint()
tp2.location = 2048
tp2.median_point_location = 50
tp2.opacity = 176
gradient_transparency_points = [tp1, tp2]
# Add stroke to layer 1
stroke = image.layers[1].blending_options.add_stroke(FillType.GRADIENT)
stroke.size = 3
gradient_fill = cast(GradientFillSettings, stroke.fill_settings)
gradient_fill.color_points = gradient_color_points
gradient_fill.transparency_points = gradient_transparency_points
# Add inner shadow to layer 2
inner_shadow = image.layers[2].blending_options.add_inner_shadow()
inner_shadow.angle = 60
inner_shadow.color = Color.yellow
# Add drop shadow to layer 3
drop_shadow = image.layers[3].blending_options.add_drop_shadow()
drop_shadow.angle = 30
drop_shadow.color = Color.violet
# Add gradient overlay to layer 4
gradient_overlay = image.layers[4].blending_options.add_gradient_overlay()
gradient_overlay.settings.color_points = gradient_color_points
gradient_overlay.settings.transparency_points = gradient_transparency_points
# Add color overlay to layer 5
color_overlay = image.layers[5].blending_options.add_color_overlay()
color_overlay.color = Color.azure
color_overlay.opacity = 120
# Add pattern overlay to layer 6
pattern_overlay = image.layers[6].blending_options.add_pattern_overlay()
patSettings = cast(PatternFillSettings, pattern_overlay.settings)
patSettings.pattern_data = [
Color.red.to_argb(), Color.transparent.to_argb(),
Color.transparent.to_argb(), Color.red.to_argb()
]
patSettings.pattern_width = 2
patSettings.pattern_height = 2
# Add outer glow to layer 7
outer_glow = image.layers[7].blending_options.add_outer_glow()
outer_glow.size = 10
outer_glow.fill_color = ColorFillSettings()
outer_glow.fill_color.color = Color.crimson
# Call the save method to save the modified image as PNG.
image.save("ines_mod.psd")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment