Title: | Simple Unified Interface to Read Bitmap Images (BMP,JPEG,PNG,TIFF) |
---|---|
Description: | Identifies and reads Windows BMP, JPEG, PNG, and TIFF format bitmap images. Identification defaults to the use of the magic number embedded in the file rather than the file extension. Reading of JPEG and PNG image depends on libjpg and libpng libraries. See file INSTALL for details if necessary. |
Authors: | Gregory Jefferis [aut, cre] , Derek Ogle [ctb], Simon Barthelme [ctb] |
Maintainer: | Gregory Jefferis <[email protected]> |
License: | GPL (>=2) |
Version: | 0.1.5 |
Built: | 2024-11-05 05:43:28 UTC |
Source: | https://github.com/jefferis/readbitmap |
The readbitmap package enables users to read the three main general purpose
bitmap image formats (jpeg, png, bmp) without having to specify the image
type directly. This is provided by a single function
read.bitmap
, which uses a second function
image_type
, which is also exported for users, to identify the
image type of a file using appropriate magic values encoded in the
first few bytes of the image header. Images can therefore have any file
extension.
Currently works for png, jpeg, BMP, and tiff images. Will seek to start of file if passed a connection. For details of magic values for files, see e.g. http://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files
image_type(source, Verbose = FALSE)
image_type(source, Verbose = FALSE)
source |
Path to file or connection |
Verbose |
Whether to write a message to console on failure (Default
|
character value corresponding to standard file extension of image
format (i.e. jpg, png, bmp, tif) or NA_character_
on failure.
jpegfile=system.file("img", "Rlogo.jpg", package="jpeg") image_type(jpegfile) jpeg_pretending_to_be_png=tempfile(fileext = '.png') file.copy(jpegfile, jpeg_pretending_to_be_png) image_type(jpeg_pretending_to_be_png) unlink(jpeg_pretending_to_be_png)
jpegfile=system.file("img", "Rlogo.jpg", package="jpeg") image_type(jpegfile) jpeg_pretending_to_be_png=tempfile(fileext = '.png') file.copy(jpegfile, jpeg_pretending_to_be_png) image_type(jpeg_pretending_to_be_png) unlink(jpeg_pretending_to_be_png)
By default uses magic bytes at the start of the file to identify the image type (rather than the file extension). Currently uses readers in bmp, jpeg, png, and tiff packages.
read.bitmap(f, channel, IdentifyByExtension = FALSE, ...)
read.bitmap(f, channel, IdentifyByExtension = FALSE, ...)
f |
Path to image file |
channel |
Integer identifying channel to return for an RGB image |
IdentifyByExtension |
Identify by file extension only (Default FALSE) |
... |
Additional parameters passed to underlying image readers |
Objects returned by readJPEG
,
readPNG
, read.bmp
, or
readTIFF
. See their documentation for details.
image_type
, readJPEG
,
readPNG
, read.bmp
,
readTIFF
img1=read.bitmap(system.file("img", "Rlogo.jpg", package="jpeg")) str(img1) img2 <- read.bitmap(system.file("img", "Rlogo.png", package="png")) # nb the PNG image has an alpha channel str(img2)
img1=read.bitmap(system.file("img", "Rlogo.jpg", package="jpeg")) str(img1) img2 <- read.bitmap(system.file("img", "Rlogo.png", package="png")) # nb the PNG image has an alpha channel str(img2)