Animation
Contents
[
Hide
]
Shows how to create simple animations and manage their sequence using Aspose.Slides for PHP via Java.
Add an Animation
Create a rectangle shape and apply a fade-in effect triggered on click.
function addAnimation() {
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$shape = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 50, 50, 100, 100);
// Fade in effect.
$slide->getTimeline()->getMainSequence()->addEffect($shape, EffectType::Fade, EffectSubtype::None, EffectTriggerType::OnClick);
$presentation->save("animation.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
}
Access an Animation
Retrieve the first animation effect from the slide timeline.
function accessAnimation() {
$presentation = new Presentation("animation.pptx");
try {
$slide = $presentation->getSlides()->get_Item(0);
// Access the first animation effect.
$effect = $slide->getTimeline()->getMainSequence()->get_Item(0);
} finally {
$presentation->dispose();
}
}
Remove an Animation
Remove an animation effect from the sequence.
function removeAnimation() {
$presentation = new Presentation("animation.pptx");
try {
$slide = $presentation->getSlides()->get_Item(0);
$effect = $slide->getTimeline()->getMainSequence()->get_Item(0);
// Remove the effect.
$slide->getTimeline()->getMainSequence()->remove($effect);
$presentation->save("animation_removed.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
}
Sequence Animations
Add multiple effects and demonstrate the order in which animations occur.
function sequenceAnimations() {
$presentation = new Presentation();
try {
$slide = $presentation->getSlides()->get_Item(0);
$shape1 = $slide->getShapes()->addAutoShape(ShapeType::Rectangle, 50, 50, 100, 100);
$shape2 = $slide->getShapes()->addAutoShape(ShapeType::Ellipse, 200, 50, 100, 100);
$sequence = $slide->getTimeline()->getMainSequence();
$sequence->addEffect($shape1, EffectType::Fly, EffectSubtype::Bottom, EffectTriggerType::OnClick);
$sequence->addEffect($shape2, EffectType::Fly, EffectSubtype::Bottom, EffectTriggerType::OnClick);
$presentation->save("animation_sequence.pptx", SaveFormat::Pptx);
} finally {
$presentation->dispose();
}
}