Title: | Dependency-Free Access to PNG Image Files |
---|---|
Description: | Read and write access to PNG image files using the LodePNG library. The package has no external dependencies. |
Authors: | Jon Clayden [aut, cre], Lode Vandevenne [aut] |
Maintainer: | Jon Clayden <[email protected]> |
License: | BSD_3_clause + file LICENCE |
Version: | 0.2.1 |
Built: | 2025-01-30 05:07:19 UTC |
Source: | https://github.com/jonclayden/loder |
Inspect a PNG file, returning parsed metadata relating to it.
inspectPng(file) ## S3 method for class 'lodermeta' print(x, ...)
inspectPng(file) ## S3 method for class 'lodermeta' print(x, ...)
file |
A character string giving the file name to read from. |
x |
An object of class |
... |
Additional arguments (which are ignored). |
The LodePNG library is used to parse the PNG file at the specified path.
The result is a string like the input, but of class "lodermeta"
and
with several attributes set describing the file's contents. There is a
print
method for these objects.
inspectPng
returns a character vector of class
"lodermeta"
. The print
method is called for its side-effect.
readPng
to read the pixel values.
path <- system.file("extdata", "pngsuite", package="loder") inspectPng(file.path(path, "basn6a08.png"))
path <- system.file("extdata", "pngsuite", package="loder") inspectPng(file.path(path, "basn6a08.png"))
Read an image from a PNG file and convert the pixel data into an R array.
readPng(file) ## S3 method for class 'loder' print(x, ...)
readPng(file) ## S3 method for class 'loder' print(x, ...)
file |
A character string giving the file name to read from. |
x |
An object of class |
... |
Additional arguments (which are ignored). |
The LodePNG library is used to read the PNG file at the specified path. LodePNG can handle a wide variety of subformats and bit depths, but the output of this function is currently standardised to an integer-mode array with 8-bit range, i.e. between 0 and 255. Attributes specifying the background colour, spatial resolution and/or aspect ratio are attached to the result if this information is stored with the image.
readPng
returns an integer-mode array of class
"loder"
. The print
method is called for its side-effect.
inspectPng
to read only metadata from the file. In addition,
the readPNG
function in the venerable png
package offers
similar functionality to readPng
, but relies on an external
installation of libpng. By contrast, loder
includes the LodePNG
library.
path <- system.file("extdata", "pngsuite", package="loder") image <- readPng(file.path(path, "basn6a08.png")) print(image) attributes(image)
path <- system.file("extdata", "pngsuite", package="loder") image <- readPng(file.path(path, "basn6a08.png")) print(image) attributes(image)
Write a numeric or logical array to a PNG file.
writePng(image, file, ..., compression = 4L, interlace = FALSE)
writePng(image, file, ..., compression = 4L, interlace = FALSE)
image |
An array containing the pixel data. |
file |
A character string giving the file name to write to. |
... |
Additional metadata elements, which override equivalently named
attributes of |
compression |
Compression level, an integer value between 0 (no compression, fastest) and 6 (maximum compression, slowest). |
interlace |
Logical value: should the image be interlaced? |
The LodePNG library is used to write a PNG file at the specified path. The source data should be of logical, integer or numeric mode. Metadata attributes of the image will be stored where applicable, and may be overwritten using named arguments. LodePNG will choose the bit depth of the final image.
Attributes which are currently stored are as follows. In each case an argument of the appropriate name can be used to override a value stored with the image.
range
A numeric 2-vector giving the extremes of the intensity window, i.e. the black and white points. Values outside this range will be clipped.
background
A hexadecimal colour string giving the background colour.
dpi
A numeric 2-vector giving the dots-per-inch resolution of the image in each dimension.
asp
The aspect ratio of the image. Ignored if dpi
is
present and valid.
text
A character vector (possibly named) of text strings to store in the file. Only ASCII and UTF-8 encoded strings are currently supported.
Dimensions are always taken from the image, and cannot be modified here.
The file
argument, invisibly.
readPng
for reading images.