Learn R Programming

bittermelon (version 2.2.1)

bm_distort: Resize bitmaps via distortion.

Description

bm_distort() resize bitmaps to arbitrary width and height value via magick::image_resize(). bm_downscale() is a wrapper to bm_distort() that downscales an image if (and only if) it is wider than a target width.

Usage

bm_distort(x, width = NULL, height = NULL, ...)

bm_downscale(x, width = getOption("width"), ...)

# S3 method for bm_bitmap bm_distort( x, width = NULL, height = NULL, ..., filter = "Point", threshold = 0.5 )

# S3 method for bm_list bm_distort(x, ...)

# S3 method for bm_pixmap bm_distort(x, width = NULL, height = NULL, ..., filter = "Point")

# S3 method for `magick-image` bm_distort(x, width = NULL, height = NULL, ..., filter = "Point")

# S3 method for nativeRaster bm_distort(x, width = NULL, height = NULL, ..., filter = "Point")

# S3 method for raster bm_distort(x, width = NULL, height = NULL, ..., filter = "Point")

Value

Depending on x either a bm_bitmap(), bm_font(), bm_list(), magick-image, "nativeRaster", bm_pixmap(), or raster object.

Arguments

x

Either a bm_bitmap(), bm_font(), bm_list(), "magick-image", "nativeRaster", bm_pixmap(), or "raster" object.

width

Desired width of bitmap

height

Desired height of bitmap

...

Additional arguments to be passed to or from methods.

filter

Passed to magick::image_resize(). Use magick::filter_types() for list of supported filters. The default "Point" filter will maintain your sprite's color palette. NULL will give you the magick's default filter which may work better if you are not trying to maintain a sprite color palette.

threshold

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

See Also

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

Examples

Run this code
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 (requireNamespace("magick", quietly = TRUE)) {
  capital_r_9x21 <- bm_distort(capital_r, width = 9L, height = 21L)
  print(capital_r_9x21)
}
crops <- farming_crops_16x16()
corn <- crops$corn$portrait
dim(corn) # 16 x 16
if (cli::is_utf8_output() &&
    cli::num_ansi_colors() >= 256L &&
    requireNamespace("magick", quietly = TRUE)) {
  corn_24x24 <- bm_distort(corn, width = 24L)
  print(corn_24x24, compress = "v")
}

Run the code above in your browser using DataLab