Skip to contents

bm_paper() infers the paper size of a bitmap (e.g. a page rendered by pdf_render_bm_pixmap()) from its aspect ratio or, if dpi is known, from its size.

Usage

bm_paper(x, ..., dpi = NULL)

Arguments

x

A bitmap object supported by {bittermelon} (e.g. a bm_pixmap, bm_bitmap, raster, nativeRaster, or magick-image object) or a bittermelon::bm_list() of such objects.

...

Ignored.

dpi

Dots per inch of x. If NULL (default) infer the paper size from the aspect ratio of x alone.

Value

A character vector with one paper size per bitmap (or per frame of a multi-frame magick-image). If dpi is NULL one of "letter", "a4", "legal", "executive", or "special" else one of the paper sizes inferred by pdf_paper().

Details

If dpi is NULL the paper size is inferred from the aspect ratio of the bitmap alone (which doesn't depend on its orientation or resolution):

  • The ISO A series paper sizes all share the same aspect ratio so they are all reported as "a4".

  • The card sizes "poker" and "bridge" are never inferred from the aspect ratio alone (pass dpi to infer them). Since a poker card's aspect ratio is within 1% of A4's a low resolution bitmap of a poker card may even be reported as "a4".

  • Bitmaps whose aspect ratio doesn't match a supported page size are reported as "special".

If dpi is given then the size of the bitmap in inches is known and the paper size is inferred the same way as pdf_paper().

See also

pdf_paper() to infer the paper size of a pdf.

Examples

if (requireNamespace("bittermelon", quietly = TRUE)) {
  f <- pdf_create_blank(paper = "a4", orientation = "portrait")
  page <- pdf_render_bm_pixmap(f, page = 1L, dpi = 50)
  bm_paper(page)
  bm_paper(page, dpi = 50)
  unlink(f)
}