Description Usage Arguments Details Value See Also Examples
View source: R/get_section_bytes.R
This package mainly focuses on parsing Exif data but
there may be other metadata in the file. This
function allows you to extract the bytes for a section
identified by scan_jpeg()
.
1 | get_section_bytes(section, input = NULL, include_marker = FALSE)
|
section |
An object of class "jpeg_section" |
input |
A character vector or seek-able binary connection |
include_marker |
By default the bytes are returned without the two-byte marker identifier. Set to TRUE to include this value |
Note that raw bytes for each section are not saved
by default. So you will need to pass the same path
used during the scan to the input=
parameter.
A raw vector
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | path <- system.file("extdata", "LookUp.jpg", package="readexif")
toc <- scan_jpeg(path)
toc # note the 4th block contains adobe XMP data
bytes <- get_section_bytes(toc[[4]], path, include_marker=TRUE)
read_xmp <- function(bytes) {
bytes <- c(bytes, as.raw(0L)) # pad with null byte
# Use connection to keep track of bytes
rawcon <- rawConnection(bytes)
on.exit(close(rawcon))
# Read section length
len <- readBin(rawcon, integer(), n=1, size=2, signed=FALSE, endian = "big")
# Read section ID
id <- readBin(rawcon, character())
# Read body. XMP happens to just use UTF-8 encoded text
body <- readBin(rawcon, character())
Encoding(body) <- "UTF-8" # (per the XMP spec)
body <- gsub("\\s{2,}", "", body) # trim excess whitespace
return(list(len=len, id=id, body=body))
}
read_xmp(bytes)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.