Nicholas Hamilton
Nicholas Hamilton

Reputation: 10516

R determine image width and height in pixels

Suppose I have an image on disk, image.jpg. How can I determine image width in pixels using R?

Upvotes: 16

Views: 9262

Answers (1)

nico
nico

Reputation: 51670

You can use the jpeg package. Code should be pretty self-explanatory:

require(jpeg)
img <- readJPEG("myimage.jpg") 

dim(img)
[1] 700 700   3

The same author (Simon Urbanek) also provided the png and tiff package, that have functions with similar syntax (readPNG and readTIFF)

Upvotes: 19

Related Questions