PhxMediaLibrary.Webp (PhxMediaLibrary v0.8.0)

Copy Markdown View Source

WebP transcoding for media originals (0.8).

Used both on add (PhxMediaLibrary.MediaAdder) and for bulk re-generation (mix phx_media_library.regenerate). Encapsulates the encode + store + record so the two call sites stay in sync.

Summary

Functions

Whether a MIME type can be transcoded to WebP.

Transcode source_path (a local file) to WebP and store it beside the original at orig_storage_path (…/name.webp), recording it in custom_properties["webp"] so URL helpers serve it. settings carries :quality.

Functions

convertible?(mime)

@spec convertible?(String.t()) :: boolean()

Whether a MIME type can be transcoded to WebP.

generate(media, source_path, settings, storage, orig_storage_path)

@spec generate(map(), String.t(), keyword(), term(), String.t()) :: map()

Transcode source_path (a local file) to WebP and store it beside the original at orig_storage_path (…/name.webp), recording it in custom_properties["webp"] so URL helpers serve it. settings carries :quality.

The source file is always kept here — for keep_original: false the original is removed later by the add flow, after conversions run (so conversions still derive from the original and nothing is deleted before them).

Returns the updated media, or the media unchanged on any processor/storage error (graceful degradation — the original is still served).