bm_distort: Resize images via distortion.

Description Usage Arguments Details Value See Also Examples

View source: R/bm_distort.R

Description

bm_distort() resize images to arbitrary width and height value via distortion.

Usage

1
2
3
4
5
6
7
8
9
bm_distort(
  bm_object,
  width = NULL,
  height = NULL,
  interpolate = FALSE,
  vp = NULL,
  png_device = NULL,
  threshold = 0.25
)

Arguments

bm_object

Either a bm_bitmap(), bm_list(), or bm_font() object.

width

Desired width of bitmap

height

Desired height of bitmap

interpolate

Passed to grid::grid.raster().

vp

A grid::viewport() object that could be used to further manipulate the image.

png_device

A function taking arguments filename, width, and height that starts a graphics device that saves a png image with a transparent background. By default will use ragg::agg_png() if available else the “cairo” version of grDevices::png() if available else just grDevices::png().

threshold

If any png channel weakly exceeds this threshold (on an interval from zero to one) then the pixel is determined to be “black”.

Details

bm_distort() generates a distorted grid::rasterGrob() with the help of as.raster.bm_bitmap() which is then converted back to a bm_bitmap() via as_bm_bitmap.grob().

Value

Either a bm_bitmap(), bm_list(), or bm_font() object.

See Also

bm_expand() for expanding width/height by integer multiples. bm_resize() for resizing an image via trimming/extending an image.

Examples

1
2
3
4
5
6
7
 font_file <- system.file("fonts/spleen/spleen-8x16.hex.gz", package = "bittermelon")
 font <- read_hex(font_file)
 capital_r <- font[[str2ucp("R")]]
 dim(capital_r) # 8 x 16
 if (require("grid") && capabilities("png")) {
   print(bm_distort(capital_r, width = 9L, height = 21L), px = px_ascii)
 }

bittermelon documentation built on Nov. 2, 2021, 1:06 a.m.