write_png | R Documentation |
Write PNG
write_png(
image,
file = NULL,
palette = NULL,
use_filter = TRUE,
compression_level = -1L,
avoid_transpose = FALSE,
bits = 8,
trns = NULL,
raw_spec = NULL
)
image |
image. Supported image types:
|
file |
If NULL (the default) then return PNG data as raw vector, otherwise write to the given file path. |
palette |
character vector of up to 256 colors. If specified, and the image is a 2D matrix of integer or numeric values, then an indexed PNG is written where the matrix values indicate the colour palette value to use. The values in the matrix must range from 0 (for the first colour) |
use_filter |
Use PNG filtering to help reduce size? Default: TRUE. If FALSE, then filtering will be disabled which can make image writing faster. |
compression_level |
compression level for PNG. Default: -1 means
to use the default compression level. Other valid
values are in range [0, 9]. In general, lower compression levels
result in faster compression, but larger image sizes. For fastest
image writing, set |
avoid_transpose |
Should transposition be avoided if possible so as to
maximise the speed of writing the PNG? Default: FALSE.
PNG is a row-major image format, but R stores data in column-major
ordering. When writing data to PNG, it is often necessary to transpose
the R data to match what PNG requires. If this option is set
to |
bits |
bit depth. default 8. Valid values are 8 and 16. This option only has an effect when image to output is a numeric array. |
trns |
color to be treated as transparent
in RGB and Greyscale images - without specifying a full alpha channel.
Only a single color can be specified and it will be treated as a
fully transparent color in the image. This setting is only used
when writing RGB and Greyscale images. For 8-bit RGB images, the value
may be a hex color value i.e. |
raw_spec |
named list of image specifications for encoding a raw vector
to PNG. Use |
If file
argument provided, function writes to file and returns
nothing, otherwise it returns a raw vector holding the PNG
encoded data.
# create a small greyscale integer matrix, and write it to a PNG file
mat <- matrix(c(0L, 255L), 3, 4)
pngfile <- tempfile()
write_png(mat, file = pngfile)
im <- read_png(pngfile, type = 'raster')
plot(im, interpolate = FALSE)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.