Podium.Image (Podium v0.3.0)

Copy Markdown View Source

Embedded image with format auto-detection from magic bytes.

Supports PNG, JPEG, BMP, GIF, TIFF, EMF, and WMF formats. Image dimensions are read from binary headers for automatic aspect-ratio sizing.

Summary

Functions

Returns the natural size of image data in EMU, as {width, height}.

Creates a new image from binary data and position options. Extension is auto-detected from magic bytes.

Returns the partname for the image media file.

Generates the <p:pic> XML for embedding the image in a slide.

Types

t()

@type t() :: %Podium.Image{
  binary: binary(),
  crop: keyword() | nil,
  extension: String.t(),
  height: non_neg_integer(),
  image_index: pos_integer() | nil,
  rotation: number() | nil,
  sha1: String.t(),
  shape: String.t(),
  width: non_neg_integer(),
  x: non_neg_integer(),
  y: non_neg_integer()
}

Functions

dimensions(binary)

@spec dimensions(binary()) :: {non_neg_integer(), non_neg_integer()}

Returns the natural size of image data in EMU, as {width, height}.

This is the size new/2 gives an image when neither :width nor :height is supplied: the pixel dimensions from the header, scaled by the image's own DPI where the format records one and 72 DPI where it does not.

Raises ArgumentError for TIFF, EMF and WMF, whose sizes this module does not read, and for data in no recognised format.

new(binary, opts)

@spec new(
  binary(),
  keyword()
) :: t()

Creates a new image from binary data and position options. Extension is auto-detected from magic bytes.

Options

  • :crop - keyword list with :left, :right, :top, :bottom (values in 1/1000ths of a percent, 0–100_000)

partname(image)

@spec partname(t()) :: String.t()

Returns the partname for the image media file.

pic_xml(image, shape_id, r_id)

@spec pic_xml(t(), pos_integer(), String.t()) :: String.t()

Generates the <p:pic> XML for embedding the image in a slide.