Creates ASCII art from an image

ascii_map(file, alphabet = letters, rescale = NULL, threshold = 0.5)

Arguments

file

A character string specifying the path to the file

alphabet

A character vector that lists the set of characters to use

rescale

Scale to resize image to (if NULL, sets maximum size of 100x100)

threshold

Lightness value at which to truncate

Value

The function returns a tibble with three variables. The x and y variables specify co-ordinates on the grid, and the label variable specifies the character that should be shown at that point. Whitespace characters are not included in the output.

Details

This is the workhorse function for the package. The user specifies the path to the image fil` as a character vector, and the function returns a tibble specifying the map. You can customise the set of characters used to render the image by changing the alphabet argument. The amount of whitespace in the ASCII image depends on the threshold parameter, which specifies the maximum brightness (in greyscale terms, from 0 to 1) at which the relevant cell in the output will be mapped to a character. Pixels in the image brighter than the threshold are automatically mapped to whitespace. Finally, you can "rescale" the input image. By default, images are rescaled so that the largest dimension is 100 pixels, but you can choose any rescaling factor you want. If your original image is 600x400 you could specify rescale = .1 which would result in a character map that is 60x40 characters is size

Examples

bayes_img <- ascii_data("bayes.png") bayes_map <- ascii_map(file = bayes_img)
#> Warning: Assuming third dimension corresponds to colour
#> Warning: Using a rescale value of 0.175
bayes_map
#> # A tibble: 1,404 x 3 #> x y label #> <int> <int> <chr> #> 1 44 2 r #> 2 45 2 v #> 3 46 2 b #> 4 47 2 e #> 5 48 2 o #> 6 41 3 y #> 7 42 3 u #> 8 43 3 e #> 9 44 3 s #> 10 45 3 o #> # … with 1,394 more rows