Suppose I have an image on disk, image.jpg
. How can I determine image width in pixels using R?
Open the page with your feed in Chrome. Right-click the image whose size you want to know and select Inspect. View your image's width and height displayed in the Chrome DevTools. (Note, the first number is always the width).
You can count this as follows: Full HD is a resolution of 1,920 by 1,080 pixels. Multiply the width of the image by its height (both in pixels) to get the pixel count. Hence, pixel count = 1,920 × 1,080 pixels .
Formula: Pixels ÷ DPI = Inches. If you know the pixel width and height of an image, this section will calculate the physical size (in inches) of the image when it is printed or displayed on various devices.
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
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With