Как да приложите 3D ефекти и сенки към форми
Aspose.Slides FOSS предоставя две независими системи за ефекти за всяка форма:
shape.effect_format: 2D визуални ефекти: външна сянка, светене, размазване, мек ръбshape.three_d_format: 3D външен вид: фаска, перспектива на камерата, осветителна система, материал, дълбочина
И двете системи могат да се комбинират върху една и съща форма.
Предварителни условия
pip install aspose-slides-fossДобавете външна падаща сянка
from aspose.slides_foss import ShapeType
from aspose.slides_foss.drawing import Color
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
shape = prs.slides[0].shapes.add_auto_shape(
ShapeType.RECTANGLE, 100, 100, 300, 120
)
shape.add_text_frame("Shadowed Shape")
ef = shape.effect_format
ef.enable_outer_shadow_effect()
ef.outer_shadow_effect.blur_radius = 10 # softness in points
ef.outer_shadow_effect.direction = 315 # 315° = upper-left
ef.outer_shadow_effect.distance = 8 # offset in points
ef.outer_shadow_effect.shadow_color.color = Color.from_argb(128, 0, 0, 0)
prs.save("shadow.pptx", SaveFormat.PPTX)Общи direction стойности: 0=дясно, 45=долу-дясно, 90=надолу, 180=ляво, 270=нагоре, 315=горе-вляво.
Добавете светлинен ефект
from aspose.slides_foss import ShapeType
from aspose.slides_foss.drawing import Color
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
shape = prs.slides[0].shapes.add_auto_shape(
ShapeType.ELLIPSE, 150, 100, 250, 250
)
ef = shape.effect_format
ef.enable_glow_effect()
ef.glow_effect.radius = 20
ef.glow_effect.color.color = Color.gold
prs.save("glow.pptx", SaveFormat.PPTX)Приложете гаусов размазък
from aspose.slides_foss import ShapeType
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
shape = prs.slides[0].shapes.add_auto_shape(
ShapeType.RECTANGLE, 100, 100, 350, 180
)
shape.effect_format.set_blur_effect(radius=10, grow=True)
prs.save("blur.pptx", SaveFormat.PPTX)grow=True разширява областта на размазване извън границата на формата; grow=False отрязва размазването вътре в формата.
Приложете 3D фаска
from aspose.slides_foss import ShapeType, BevelPresetType
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
shape = prs.slides[0].shapes.add_auto_shape(
ShapeType.RECTANGLE, 150, 150, 280, 120
)
shape.add_text_frame("3D Button")
tdf = shape.three_d_format
tdf.bevel_top.bevel_type = BevelPresetType.CIRCLE
tdf.bevel_top.width = 12
tdf.bevel_top.height = 6
prs.save("bevel.pptx", SaveFormat.PPTX)BevelPresetType стойности: CIRCLE, RELAXED_INSET, COOL_SLANT, DIVOT, RIBLET, HARD_EDGE, SLOPE, CONVEX
3D фаска с камера и осветителна система
from aspose.slides_foss import (
ShapeType, BevelPresetType, CameraPresetType,
LightRigPresetType, LightingDirection, MaterialPresetType,
)
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
shape = prs.slides[0].shapes.add_auto_shape(
ShapeType.RECTANGLE, 150, 150, 280, 120
)
shape.add_text_frame("Metal Button")
tdf = shape.three_d_format
tdf.bevel_top.bevel_type = BevelPresetType.CIRCLE
tdf.bevel_top.width = 10
tdf.bevel_top.height = 5
tdf.camera.camera_type = CameraPresetType.PERSPECTIVE_ABOVE
tdf.light_rig.light_type = LightRigPresetType.BALANCED
tdf.light_rig.direction = LightingDirection.TOP
tdf.material = MaterialPresetType.METAL
tdf.depth = 20
prs.save("3d-metal.pptx", SaveFormat.PPTX)Комбиниране на сянка и 3D фаска
Двата системи за ефекти могат да бъдат активни едновременно върху една и съща форма:
from aspose.slides_foss import (
ShapeType, FillType, BevelPresetType,
CameraPresetType, MaterialPresetType,
)
from aspose.slides_foss.drawing import Color
import aspose.slides_foss as slides
from aspose.slides_foss.export import SaveFormat
with slides.Presentation() as prs:
shape = prs.slides[0].shapes.add_auto_shape(
ShapeType.ROUND_CORNER_RECTANGLE, 150, 150, 320, 130
)
shape.add_text_frame("Premium Card")
# Solid fill
shape.fill_format.fill_type = FillType.SOLID
shape.fill_format.solid_fill_color.color = Color.from_argb(255, 30, 80, 180)
# 3D bevel
tdf = shape.three_d_format
tdf.bevel_top.bevel_type = BevelPresetType.CIRCLE
tdf.bevel_top.width = 8
tdf.camera.camera_type = CameraPresetType.PERSPECTIVE_ABOVE
tdf.material = MaterialPresetType.PLASTIC
# Drop shadow
ef = shape.effect_format
ef.enable_outer_shadow_effect()
ef.outer_shadow_effect.blur_radius = 12
ef.outer_shadow_effect.direction = 270
ef.outer_shadow_effect.distance = 6
ef.outer_shadow_effect.shadow_color.color = Color.from_argb(80, 0, 0, 0)
prs.save("premium-card.pptx", SaveFormat.PPTX)Проверка и премахване на ефекти
from aspose.slides_foss import ShapeType
import aspose.slides_foss as slides
with slides.Presentation() as prs:
shape = prs.slides[0].shapes.add_auto_shape(
ShapeType.RECTANGLE, 100, 100, 200, 100
)
ef = shape.effect_format
ef.enable_outer_shadow_effect()
ef.enable_glow_effect()
print(f"Has effects: {not ef.is_no_effects}") # True
ef.disable_outer_shadow_effect()
ef.disable_glow_effect()
print(f"Has effects: {not ef.is_no_effects}") # False