A raw pixel bitmap — produced by ExPdfium.render_page/3 (a rendered page) or
ExPdfium.image_data/3 (a decoded embedded image).
data is a raw pixel buffer. format records the byte order and channel count
so consumers can interpret it: :rgba/:bgra (4 channels), :bgrx (4, with a
padding byte), :bgr (3), or :gray (1). render_page/3 yields :rgba
(default) or :bgra; an image decoded with image_data/3 keeps its native
pdfium format. With width, height, and stride (bytes per row), the buffer
feeds directly into e.g. Vix.Vips.Image.new_from_binary/5 — or use to_vix/1,
which reads format and hands back a correctly-interpreted image (band count +
BGR→RGB), so you don't have to branch on the channel order yourself.
Summary
Functions
Convert this bitmap into a correctly-interpreted Vix.Vips.Image.
Types
@type format() :: :rgba | :bgra | :bgrx | :bgr | :gray
@type t() :: %ExPdfium.Bitmap{ data: binary(), format: format(), height: non_neg_integer(), stride: non_neg_integer(), width: non_neg_integer() }
Functions
Convert this bitmap into a correctly-interpreted Vix.Vips.Image.
Reads format so the caller doesn't have to: it sets the right band count and
reorders pdfium's native BGR channel order into RGB (:bgr, :bgrx,
:bgra), drops the padding byte of :bgrx, and passes :rgba/:gray straight
through. Row stride padding is stripped first. The result is ready for the rest
of a Vix/Image pipeline (resize, Image.write_to_file/2, …):
{:ok, bmp} = ExPdfium.image_data(doc, 0, 2)
{:ok, img} = ExPdfium.Bitmap.to_vix(bmp)
:ok = Vix.Vips.Image.write_to_file(img, "out.png")Vix is an optional dependency. If it isn't in your project, this returns
{:error, :vix_not_loaded} (add {:vix, "~> 0.39"} to your deps). Returns
{:error, :vix_failed} if libvips rejects the buffer.