How to dynamically show images using its original image dimensions?

I am using pix units to display my images. My images come in different sizes. Image paths are set on every loop based on a conditions file. In Psychopy Builder I left the image component’s Size field empty which made Psychopy Builder just use the default image dimensions as I want (i.e. would show the image as the size it actually is in my .png file). However when I export to Javascript and run on Pavlovia I get an error:

Is there an easy fix for this to force PsychoJs to just use the default image size of the .png file?

With some tinkering in the console, I found that the image’s original dimensions (learn_white_sat is my image component name) can be accessed using this JS code:

I know I can probably just use this but was wondering if there is a better/simpler way to accomplish this as it seems like a pretty simple problem, and might prevent me from having to draw from this manually in my javascript code for all my images as I continue to build my experiment in Builder.

Thank you!

Hey @mt182, would it be possible to send me a link to your experiment on Pavlovia, or the .psyexp for it so that I can investigate further? Here to help, thanks, s.

Hi thanks for the response. I ended up resolving it simply by using the method I used above (i.e. accessing the naturalHeight and naturalWidth.

1 Like