Storehouse.Image.WebP (Storehouse v0.2.0)

Copy Markdown View Source

Edits the metadata inside a WebP without re-encoding it, as Storehouse.Image.JPEG does a JPEG's: the same changes, the same tags.

A WebP keeps its metadata in chunks of its own, EXIF and XMP, which the VP8X header lists. These functions rewrite those chunks and the header's flags, and copy every other chunk, the image and what draws it (alpha, the colour profile, an animation's frames), byte for byte.

  • strip: :gps - the Exif GPS directory, zeroed, and XMP's GPS properties.
  • strip: {:keep, tags} - Exif with only the tags named, and no XMP or chunk of another app's.
  • put: %{artist: _, copyright: _, image_description: _} - written into Exif. A simple WebP, which has no VP8X header, is given one, from its image's size.

edit_file/3 reads only the metadata chunks into memory. A WebP whose chunks cannot be read is refused with {:error, :malformed}, one whose Exif cannot be read with {:error, :malformed_exif}.

Summary

Types

Why a WebP is refused.

Functions

The WebP with changes made (Storehouse.Image.MetadataEditor): :strip, then :put.

The WebP at from, with changes made (as edit/2), written to to, with only its metadata in memory. :unchanged when there is nothing to change, and to is not written.

The named tags its Exif has (Storehouse.Image.JPEG.tags/1).

Types

reason()

@type reason() :: :not_webp | :malformed | :malformed_exif

Why a WebP is refused.

Functions

edit(webp, changes)

@spec edit(binary(), Storehouse.Image.MetadataEditor.changes()) ::
  {:ok, binary()} | {:error, reason()}

The WebP with changes made (Storehouse.Image.MetadataEditor): :strip, then :put.

edit_file(from, to, changes)

@spec edit_file(Path.t(), Path.t(), Storehouse.Image.MetadataEditor.changes()) ::
  :ok | :unchanged | {:error, reason() | File.posix()}

The WebP at from, with changes made (as edit/2), written to to, with only its metadata in memory. :unchanged when there is nothing to change, and to is not written.

tags(webp)

@spec tags(binary()) :: {:ok, map()} | {:error, reason()}

The named tags its Exif has (Storehouse.Image.JPEG.tags/1).