BaileysEx.Media.Thumbnail (baileys_ex v0.1.0-alpha.8)

Copy Markdown View Source

Generate media derivatives used by WhatsApp media messages.

Image thumbnails use the optional Image package when it is available. Video thumbnails and audio waveforms use ffmpeg when it is available. Missing runtime tools return explicit dependency errors instead of crashing.

Summary

Functions

Generate a 64-sample WhatsApp-style waveform from an audio file or binary.

Extract image dimensions from PNG, JPEG, or WebP binary data.

Generate a JPEG thumbnail for an image binary.

Generate a JPEG thumbnail from a video file.

Types

derivative_error()

@type derivative_error() ::
  :invalid_audio_payload
  | :unsupported_image_format
  | {:ffmpeg_failed, term()}
  | {:image_processing_failed, term()}
  | {:missing_dependency, :ffmpeg | :image}

thumbnail_result()

@type thumbnail_result() :: %{
  jpeg_thumbnail: binary(),
  width: pos_integer(),
  height: pos_integer()
}

Functions

audio_waveform(audio_input, opts \\ [])

@spec audio_waveform(
  binary() | Path.t(),
  keyword()
) :: {:ok, binary()} | {:error, derivative_error()}

Generate a 64-sample WhatsApp-style waveform from an audio file or binary.

The returned waveform is a 64-byte binary with values in the 0..100 range.

image_dimensions(image_data)

@spec image_dimensions(binary()) ::
  {:ok, {pos_integer(), pos_integer()}} | {:error, :unsupported_image_format}

Extract image dimensions from PNG, JPEG, or WebP binary data.

image_thumbnail(image_data, opts \\ [])

@spec image_thumbnail(
  binary(),
  keyword()
) :: {:ok, thumbnail_result()} | {:error, derivative_error()}

Generate a JPEG thumbnail for an image binary.

Returns the generated thumbnail bytes along with the original image dimensions, matching the metadata Baileys uses later in message building.

video_thumbnail(video_path, opts \\ [])

@spec video_thumbnail(
  Path.t(),
  keyword()
) :: {:ok, thumbnail_result()} | {:error, derivative_error()}

Generate a JPEG thumbnail from a video file.

This shells out to ffmpeg and returns the generated thumbnail bytes along with the thumbnail dimensions.