How can I get the width and height of an image based on image path?


Is there any way to get dimensions(width and height) of the image by giving the path?



You can use the ImageSource module.

fromFile(path).width // or .height


I tried that but getting this error

TypeError: null is not an object (evaluating ‘fromFile.width’)

This is how the path looks like


You never mentioned its a remote image, you can’t read it’s width until it’s downloaded. Use fromUrl,

.then((imageSource) => {
 imageSource.width // or .height


Yay its working for remote images. should I use ‘fromFile’ for local paths then?


Yes, fromFile is for local images.


I am getting the width and height. can you confirm that in which format the width and height are Pixels or DIPS ?


It should be pixels.



Looks like it is in DIPs. Also if the image is overflowing out of the parent then the image dimensions we fetching here is not correct (I believe that the extra image part which is out of the parent is not being considered as part of the whole image, in dimensions calculations).



Just now found that, I am actually getting the 90% of the device dimension values. For example (in my case) :

deviceWidth * .9 => imageWidth (320 * .9 = 288)
deviceHeight * .9 => imageHeight (568 * .9 = 512)

This is strange!

Please help.


Try to update this example, if the issue is reproduce please let us know.