Skip to main content

GifEncoder

Trait GifEncoder 

Source
pub trait GifEncoder: Send + Sync {
    // Required methods
    fn encode(
        &self,
        frames: &[EncodableFrame],
        config: &EncodeConfig,
    ) -> Result<Vec<u8>>;
    fn encode_to_file(
        &self,
        frames: &[EncodableFrame],
        path: impl AsRef<Path>,
        config: &EncodeConfig,
    ) -> Result<()>;
    fn encode_to_writer<W: Write>(
        &self,
        frames: &[EncodableFrame],
        writer: W,
        config: &EncodeConfig,
    ) -> Result<()>;
    fn supports_lossy(&self) -> bool;
    fn name(&self) -> &'static str;
}
Expand description

Trait for encoding frames into GIF format.

Implementations can provide different encoding strategies:

  • Standard lossless GIF encoding
  • Lossy encoding for smaller file sizes
  • High-quality encoding with dithering

§Example

use figif_core::traits::GifEncoder;
use figif_core::encoders::StandardEncoder;

let encoder = StandardEncoder::new();
let bytes = encoder.encode(&frames, &EncodeConfig::default())?;

Required Methods§

Source

fn encode( &self, frames: &[EncodableFrame], config: &EncodeConfig, ) -> Result<Vec<u8>>

Encode frames to a byte vector.

Source

fn encode_to_file( &self, frames: &[EncodableFrame], path: impl AsRef<Path>, config: &EncodeConfig, ) -> Result<()>

Encode frames to a file.

Source

fn encode_to_writer<W: Write>( &self, frames: &[EncodableFrame], writer: W, config: &EncodeConfig, ) -> Result<()>

Encode frames to any writer.

Source

fn supports_lossy(&self) -> bool

Whether this encoder supports lossy compression.

Source

fn name(&self) -> &'static str

Get the name of this encoder for logging/debugging.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§