PPTX

效果与填充

为形状应用阴影、发光、3D 效果和各种填充类型

通过视觉效果(阴影、发光、3D)和填充(纯色、渐变、图片、透明)增强形状。

纯色填充

import { generatePresentation } from "@office-open/pptx";
{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "10.6cm",
            "height": "6.6cm",
            "fill": { "type": "solid", "color": "2E74B5" }
          }
        }
      ]
    }
  ]
}

简写形式 -- 直接传入颜色字符串:

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "10.6cm",
            "height": "6.6cm",
            "fill": "2E74B5"
          }
        }
      ]
    }
  ]
}

渐变填充

线性渐变(带角度)

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "15.9cm",
            "height": "6.6cm",
            "fill": {
              "type": "gradient",
              "stops": [
                { "position": 0, "color": "0D47A1" },
                { "position": 100, "color": "42A5F5" }
              ],
              "angle": 45
            }
          }
        }
      ]
    }
  ]
}

径向渐变(带路径)

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "10.6cm",
            "height": "10.6cm",
            "geometry": "ellipse",
            "fill": {
              "type": "gradient",
              "stops": [
                { "position": 0, "color": "FFFFFF" },
                { "position": 100, "color": "1565C0" }
              ],
              "path": "circle"
            }
          }
        }
      ]
    }
  ]
}

多色标渐变

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "15.9cm",
            "height": "6.6cm",
            "fill": {
              "type": "gradient",
              "stops": [
                { "position": 0, "color": "E53935" },
                { "position": 50, "color": "FF9800" },
                { "position": 100, "color": "FFEB3B" }
              ],
              "angle": 90
            }
          }
        }
      ]
    }
  ]
}

图片填充(Blip Fill)

data 字段接受原始字节(Uint8ArrayArrayBufferBuffer),也支持 base64 data URL(如 data:image/png;base64,...)。

import * as fs from "node:fs";
{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "15.9cm",
            "height": "9.3cm",
            "fill": {
              "type": "blip",
              "data": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=",
              "imageType": "png"
            }
          }
        }
      ]
    }
  ]
}

无填充(透明)

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "13.2cm",
            "height": "6.6cm",
            "fill": { "type": "none" },
            "outline": { "color": "2E74B5", "width": 2 }
          }
        }
      ]
    }
  ]
}

轮廓

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "13.2cm",
            "height": "6.6cm",
            "fill": { "type": "solid", "color": "E3F2FD" },
            "outline": {
              "color": "1565C0",
              "width": "0.1cm",
              "dashStyle": "solid"
            }
          }
        }
      ]
    }
  ]
}

效果

使用 effects 属性控制阴影、发光、倒影、柔化边缘和 3D 效果:

外部阴影

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "3.2cm",
            "fill": "ED7D31",
            "effects": {
              "outerShadow": {
                "blur": 50800,
                "distance": 38100,
                "direction": 5400000,
                "color": "000000",
                "alpha": 50
              }
            }
          }
        }
      ]
    }
  ]
}

内部阴影

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "3.2cm",
            "fill": "5B9BD5",
            "effects": {
              "innerShadow": {
                "blur": 40000,
                "distance": 30000,
                "direction": 5400000,
                "color": "000000",
                "alpha": 40
              }
            }
          }
        }
      ]
    }
  ]
}

发光

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "3.2cm",
            "fill": "70AD47",
            "effects": {
              "glow": {
                "radius": 152400,
                "color": "92D050",
                "alpha": 60
              }
            }
          }
        }
      ]
    }
  ]
}

倒影

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "3.2cm",
            "fill": "FFC000",
            "effects": {
              "reflection": {
                "blurRadius": 6350,
                "distance": 38100,
                "direction": 5400000,
                "startAlpha": 90,
                "endAlpha": 0
              }
            }
          }
        }
      ]
    }
  ]
}

柔化边缘

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "3.2cm",
            "fill": "BF8F00",
            "effects": {
              "softEdge": { "radius": 50800 }
            }
          }
        }
      ]
    }
  ]
}

3D 旋转和斜面

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "4.0cm",
            "fill": "FFC000",
            "effects": {
              "rotation3D": {
                "x": "0.5cm",
                "y": "0.8cm",
                "z": 10,
                "perspective": 500
              },
              "bevelTop": { "width": 8, "height": 8 },
              "extrusionH": 50000,
              "material": "plastic"
            }
          }
        }
      ]
    }
  ]
}

组合效果

可以同时应用多种效果:

{
  "slides": [
    {
      "children": [
        {
          "shape": {
            "x": "1.3cm",
            "y": "1.3cm",
            "width": "5.3cm",
            "height": "3.2cm",
            "fill": "7030A0",
            "effects": {
              "outerShadow": {
                "blur": 40000,
                "distance": 30000,
                "direction": 2700000,
                "color": "000000",
                "alpha": 40
              },
              "glow": { "radius": 101600, "color": "B381E7", "alpha": 35 }
            }
          }
        }
      ]
    }
  ]
}

Effects 选项

属性类型说明
outerShadowShadowOptions外部阴影
innerShadowShadowOptions内部阴影
glowGlowOptions发光效果
reflectionReflectionOptions倒影效果
softEdgeSoftEdgeOptions柔化边缘效果
rotation3DRotation3DOptions3D 旋转
bevelTopPPTXBevelOptions顶部斜面
bevelBottomPPTXBevelOptions底部斜面
extrusionHnumber挤出高度(EMU)
materialstring材质类型
lightingstring灯光类型
Copyright © 2026