Stores images registered inside a PDF document.
Images are indexed by their content hash so the same image can be reused across multiple pages without being embedded more than once.
Resource names are generated sequentially:
Im1
Im2
Im3
Summary
Functions
Returns all registered images sorted by their resource number.
Returns the number of registered images.
Fetches a registered image by hash.
Fetches a registered image and raises when it does not exist.
Returns every registered image hash.
Creates an empty image registry.
Returns the resource name that will be assigned to the next new image.
Adds an image directly to the registry.
Registers an image.
Returns whether an image hash is already registered.
Creates an /XObject resource dictionary for selected image hashes.
Types
@type t() :: %PaperForge.ImageRegistry{ images: %{optional(binary()) => PaperForge.Image.t()}, next_resource_id: pos_integer() }
Functions
@spec all(t()) :: [PaperForge.Image.t()]
Returns all registered images sorted by their resource number.
@spec count(t()) :: non_neg_integer()
Returns the number of registered images.
@spec fetch(t(), binary()) :: {:ok, PaperForge.Image.t()} | :error
Fetches a registered image by hash.
Returns {:ok, image} or :error.
@spec fetch!(t(), binary()) :: PaperForge.Image.t()
Fetches a registered image and raises when it does not exist.
Returns every registered image hash.
@spec new() :: t()
Creates an empty image registry.
Returns the resource name that will be assigned to the next new image.
Example
PaperForge.ImageRegistry.next_resource_name(registry)
#=> "Im1"
@spec put(t(), PaperForge.Image.t()) :: t()
Adds an image directly to the registry.
This is similar to register/2, but always replaces an existing image
with the same hash.
@spec register(t(), PaperForge.Image.t()) :: {t(), PaperForge.Image.t()}
Registers an image.
When an image with the same hash already exists, the existing image and unchanged registry are returned.
Example
{registry, image} =
PaperForge.ImageRegistry.register(
registry,
image
)
Returns whether an image hash is already registered.
Creates an /XObject resource dictionary for selected image hashes.
Duplicate hashes are ignored.
Example result
%{
"Im1" => %PaperForge.Reference{
object_id: 8,
generation: 0
}
}