[R] determine size (width and height) of a graphics file via R - how?

Ethan Brown ethancbrown at gmail.com
Mon May 14 23:21:03 CEST 2012


Hi Mark,

You can do this easily with the "identify" command in ImageMagick
<http://www.imagemagick.org>. Install it, and then from within an R
session:

system2("identify", "yourimagename.jpg")

...and it should give you something like this:

yourimagename.jpg JPEG 800x533 800x533+0+0 8-bit DirectClass 378KB
0.000u 0:00.019

...which is overkill but does include the dimensions.

If you're on Windows you need an extra argument:

system2("identify", "yourimagename.jpg", invisible = FALSE)

to make sure it actually shows you the result.

EBImage is an R interface to imagemagick but is probably more trouble
than it's worth for the simple task you're trying to do.

Hope this helps,
Ethan

On Sun, May 13, 2012 at 6:57 AM, Mark Heckmann <mark.heckmann at gmx.de> wrote:
> Hi,
>
> is there a way to determine the size (width, height) of a graphics file saved on my hard disk, e.g. a .bmp, via R.
> What I want is basically the same information on the dimensions of the graphic file that I get from my file browser.
>
> Thanks
> Mark
>
> PS. Why: I use the R2PPT and I need to determine the size of the original graphic before adding it to a slide.
>
> 末末末末末末末末末末末末末末末末末末
> Mark Heckmann
> Blog: www.markheckmann.de
> R-Blog: http://ryouready.wordpress.com
>
>
>
>
>
>
>
>
>
>
>
>        [[alternative HTML version deleted]]
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list