在演示文稿中使用 PHP 应用形状效果

虽然 PowerPoint 中的效果可用于突出形状,但它们不同于 填充 或轮廓。使用 PowerPoint 效果,您可以在形状上创建逼真的倒影,扩散形状的光晕等。

shape-effect

  • PowerPoint 提供六种可应用于形状的效果。您可以对一个形状应用一个或多个效果。
  • 某些效果组合看起来比其他组合更好。因此,PowerPoint 在 Preset 下提供选项。Preset 选项本质上是两个或多个效果的已知好看组合。通过选择预设,您无需浪费时间测试或组合不同的效果来寻找合适的组合。

Aspose.Slides 在 EffectFormat 类下提供属性和方法,允许您在 PowerPoint 演示文稿中对形状应用相同的效果。

应用阴影效果

此 PHP 代码示例演示如何将外阴影效果(OuterShadowEffect) 应用于矩形:

  $pres = new Presentation();
  try {
    $shape = $pres->getSlides()->get_Item(0)->getShapes()->addAutoShape(ShapeType::RoundCornerRectangle, 20, 20, 200, 150);
    $shape->getEffectFormat()->enableOuterShadowEffect();
    $shape->getEffectFormat()->getOuterShadowEffect()->getShadowColor()->setColor(java("java.awt.Color")->DARK_GRAY);
    $shape->getEffectFormat()->getOuterShadowEffect()->setDistance(10);
    $shape->getEffectFormat()->getOuterShadowEffect()->setDirection(45);
    $pres->save("output.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

应用反射效果

此 PHP 代码示例演示如何将反射效果应用于形状:

  $pres = new Presentation();
  try {
    $shape = $pres->getSlides()->get_Item(0)->getShapes()->addAutoShape(ShapeType::RoundCornerRectangle, 20, 20, 200, 150);
    $shape->getEffectFormat()->enableReflectionEffect();
    $shape->getEffectFormat()->getReflectionEffect()->setRectangleAlign(RectangleAlignment->Bottom);
    $shape->getEffectFormat()->getReflectionEffect()->setDirection(90);
    $shape->getEffectFormat()->getReflectionEffect()->setDistance(55);
    $shape->getEffectFormat()->getReflectionEffect()->setBlurRadius(4);
    $pres->save("reflection.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

应用光晕效果

此 PHP 代码示例演示如何将光晕效果应用于形状:

  $pres = new Presentation();
  try {
    $shape = $pres->getSlides()->get_Item(0)->getShapes()->addAutoShape(ShapeType::RoundCornerRectangle, 20, 20, 200, 150);
    $shape->getEffectFormat()->enableGlowEffect();
    $shape->getEffectFormat()->getGlowEffect()->getColor()->setColor(java("java.awt.Color")->MAGENTA);
    $shape->getEffectFormat()->getGlowEffect()->setRadius(15);
    $pres->save("glow.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

应用柔化边缘效果

此 PHP 代码示例演示如何将柔化边缘应用于形状:

  $pres = new Presentation();
  try {
    $shape = $pres->getSlides()->get_Item(0)->getShapes()->addAutoShape(ShapeType::RoundCornerRectangle, 20, 20, 200, 150);
    $shape->getEffectFormat()->enableSoftEdgeEffect();
    $shape->getEffectFormat()->getSoftEdgeEffect()->setRadius(15);
    $pres->save("softEdges.pptx", SaveFormat::Pptx);
  } finally {
    if (!java_is_null($pres)) {
      $pres->dispose();
    }
  }

常见问题

我可以对同一形状应用多个效果吗?

可以,您可以在单个形状上组合不同的效果,例如阴影、反射和光晕,以创建更具动感的外观。

哪些形状可以应用效果?

您可以对各种形状应用效果,包括自动形状、图表、表格、图片、SmartArt 对象、OLE 对象等。

我可以对组合形状应用效果吗?

可以,您可以对组合形状应用效果。效果将应用于整个组合。