Jump to content

Is it possible to read a texture's resolution from JavaScript?


Recommended Posts

I have an image GUI object and would like to dynamically resize it to its texture's aspect ratio. Is it possible to read an image file's resolution in JavaScript or does it require editing the C++ source code?

Link to comment
Share on other sites

Not possible directly. But maybe you can hack it around and implicitly get the values by creating a parent object that you can get it GUISize from Engine.getGUIObject(...) javascript call and have the children object centered & have the image at 1:1 ratio (I think you an customize the ratio by adding some string at the end, check the C++ code). Then by iterative approximation calculate when the parent object matches the child object size. Thus you will have the ratio (but not the real resolution).

Another easier solution is to set all your textures to the same aspect ration so you can know it in advance. 

Edited by nani
Link to comment
Share on other sites

 

1 hour ago, nani said:

But maybe you can hack it around and implicitly get the values by creating a parent object that you can get it GUISize from Engine.getGUIObject(...) javascript call and have the children object centered & have the image at 1:1 ratio (I think you an customize the ratio by adding some string at the end, check the C++ code). Then by iterative approximation calculate when the parent object matches the child object size. Thus you will have the ratio (but not the real resolution).

Not exactly sure if I understand that correctly, what appendage string do you mean?

Maybe the best way would be  to simply store the images' resolutions somewhere in a file and read it from there.

Edited by Vantha
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...