Load PNG, JPG, BMP or GIF from disk or URL.

image_load(file)

Arguments

file

character, file name. A local file or URL. Extension must be one of png, jpg, jpeg, bmp or gif.

Value

an RBG array

Details

The function will prompt you of the need to install a format-specific package if not installed and needed for the given file extension; png, bmp, magick (for GIF). jpeg is already imported for purpose of running examples.

Examples

x <- paste0(system.file(package = "imgpalr"), "/blue-yellow.",
  c("jpg", "png", "bmp", "gif"))
str(image_load(x[1]))
#>  num [1:317, 1:400, 1:3] 0.216 0.149 0.125 0.161 0.157 ...
if(require(png)) str(image_load(x[2]))
#> Loading required package: png
#>  num [1:158, 1:200, 1:3] 0.153 0.122 0.137 0.133 0.208 ...
if(require(bmp)) str(image_load(x[3]))
#> Loading required package: bmp
#>  num [1:158, 1:200, 1:3] 0.153 0.122 0.137 0.133 0.208 ...
#>  - attr(*, "header")=List of 13
#>   ..$ filesize     : num 94854
#>   ..$ offset       : num 54
#>   ..$ header_sz    : num 40
#>   ..$ width        : num 200
#>   ..$ height       : num 158
#>   ..$ nplanes      : int 1
#>   ..$ depth        : int 24
#>   ..$ compress_type: num 0
#>   ..$ bmp_bytesz   : num 94800
#>   ..$ hres         : num 2835
#>   ..$ vres         : num 2835
#>   ..$ ncolors      : num 0
#>   ..$ nimpcolors   : num 0
if(require(magick)) str(image_load(x[4]))
#> Loading required package: magick
#> Linking to ImageMagick 6.9.12.93
#> Enabled features: cairo, freetype, fftw, ghostscript, heic, lcms, pango, raw, rsvg, webp
#> Disabled features: fontconfig, x11
#>  num [1:158, 1:200, 1:3] 0.129 0.102 0.114 0.129 0.196 ...