Edit

Share via


PowerPoint.ShapeGetImageOptions interface

Represents the available options when getting an image of a shape. The image is scaled to fit into the desired dimensions. If width and height aren't specified, the true size of the shape is used. If only one of either width or height is specified, the other will be calculated to preserve aspect ratio. The resulting dimensions will automatically be clamped to the maximum supported size if too large.

Remarks

[ API set: PowerPointApi 1.10 ]

Examples

// Link to full sample: https://raw.githubusercontent.com/OfficeDev/office-js-snippets/prod/samples/powerpoint/shapes/get-shape-as-image.yaml

// Gets an image of the first selected shape with all options specified:
// a fixed width, height, and explicit PNG format.
await PowerPoint.run(async (context) => {
  const shapes: PowerPoint.ShapeScopedCollection = context.presentation.getSelectedShapes();
  const shapeCount = shapes.getCount();
  await context.sync();

  if (shapeCount.value === 0) {
    console.warn("No shapes are selected. Please select a shape and try again.");
    return;
  }

  const shape: PowerPoint.Shape = shapes.getItemAt(0);
  const options: PowerPoint.ShapeGetImageOptions = {
    format: PowerPoint.ShapeGetImageFormatType.png,
    width: 300,
    height: 150,
    // Both width and height are specified, so the image is scaled to fit within
    // 300x150 pixels. The image may not fill both dimensions if the aspect ratios differ.
  };
  const imageResult: OfficeExtension.ClientResult<string> = shape.getImageAsBase64(options);
  await context.sync();

  displayImage(imageResult.value, "PNG, 300x150px");
});

Properties

format

The desired format of the resulting image.

height

The desired height of the resulting image in pixels. This value will automatically be clamped to the maximum supported size if too large. Throws an InvalidArgument exception when set with a non-positive integer.

width

The desired width of the resulting image in pixels. This value will automatically be clamped to the maximum supported size if too large. Throws an InvalidArgument exception when set with a non-positive integer.

Property Details

format

The desired format of the resulting image.

format?: PowerPoint.ShapeGetImageFormatType | "Png";

Property Value

Remarks

[ API set: PowerPointApi 1.10 ]

height

The desired height of the resulting image in pixels. This value will automatically be clamped to the maximum supported size if too large. Throws an InvalidArgument exception when set with a non-positive integer.

height?: number;

Property Value

number

Remarks

[ API set: PowerPointApi 1.10 ]

width

The desired width of the resulting image in pixels. This value will automatically be clamped to the maximum supported size if too large. Throws an InvalidArgument exception when set with a non-positive integer.

width?: number;

Property Value

number

Remarks

[ API set: PowerPointApi 1.10 ]