Texture2D.LoadImage not giving the right dimensions of loaded image.

I am using this code to load two images and find their dimensions in pixels: img.jpg and imgFlipped.jpg.
189032-unity.png

Texture2D img = new Texture2D(1, 1);
byte[] tmpBytes = File.ReadAllBytes("Assets/Resources/Images/img.jpg");
img.LoadImage(tmpBytes);
Debug.Log("img:" + img.width + "--" + img.height);

Texture2D imgFlipped = new Texture2D(1, 1);
byte[] tmpBytesFlipped = File.ReadAllBytes("Assets/Resources/Images/imgFlipped.jpg");
imgFlipped.LoadImage(tmpBytesFlipped);
Debug.Log("imgFilpped:" + imgFlipped.width + "--" + imgFlipped.height);

imgFlipped is just as the name says; img flipped 90 degrees.
The resolution of img is 2048 x 1152 which means that imgFlipped should have a resolution of 1152 x 2048. However the output in the console is saying otherwise. It keeps the same resolution.
189031-unity.png

The goal was actually just to find pixel size of the texture I am loading.
PS: even when visualizing imgFlipped.jpg, it flips and gets visualized as img.jpg

  • What is going wrong here? Does ImageLoad consider the largest dimension as width ?
  • Is there another way to get the real dimensions of an image on the disk ?

I am not sure what the problem was.
However I could achieve what I wanted by doing this:

img = Resources.Load<Texture2D>("img");
imgFlipped = Resources.Load<Texture2D>("imgFlipped");

I think when going to the array form, using ReadAllBytes, the width and height is kinda lost.