Represents an image registered inside a PDF document.
PaperForge supports JPEG and PNG images embedded as PDF image XObjects.
A registered image contains:
- its content hash;
- original width and height;
- color space;
- bits per component;
- raw image data;
- internal PDF resource name;
- indirect object reference.
Example
%PaperForge.Image{
hash: <<...>>,
format: :png,
width: 1200,
height: 800,
color_space: :device_rgb,
bits_per_component: 8,
data: image_binary,
resource_name: "Im1",
reference: %PaperForge.Reference{
object_id: 8,
generation: 0
}
}
Summary
Functions
Calculates the display size while preserving aspect ratio when only one dimension is provided.
Returns a SHA-256 hash for image binary data.
Returns a hexadecimal representation of an image hash.
Creates a registered image.
Returns the PDF name associated with the image color space.
Types
@type color_space() :: :device_gray | :device_rgb | :device_cmyk
@type format() :: :jpeg | :png
@type t() :: %PaperForge.Image{ bits_per_component: pos_integer(), color_space: color_space(), data: binary(), format: format(), hash: binary(), height: pos_integer(), reference: PaperForge.Reference.t(), resource_name: binary(), width: pos_integer() }
Functions
Calculates the display size while preserving aspect ratio when only one dimension is provided.
Supported combinations:
- neither width nor height: use original dimensions;
- only width: calculate height;
- only height: calculate width;
- both width and height: use both values directly.
Examples
PaperForge.Image.display_size(
image,
width: 200
)
PaperForge.Image.display_size(
image,
height: 100
)
Returns a SHA-256 hash for image binary data.
This hash can be used by PaperForge.ImageRegistry to avoid storing
the same image more than once.
Returns a hexadecimal representation of an image hash.
This is mainly useful for debugging and tests.
Creates a registered image.
The metadata map must contain:
:width:height:color_space:bits_per_component
@spec pdf_color_space(t() | color_space()) :: {:name, binary()}
Returns the PDF name associated with the image color space.