Search code examples
rimageheightwidth

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?


Solution

  • 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)