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

Posted (edited)

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...