I have some images that have different sizes & aspect ratios. In my experiment, I want to present these images in their native aspect ratio. I also want to randomize their positions within a certain window on the screen, so for that I also need to know their sizes (since the range from which the center positions must be drawn is different for each image and depends on its size).
This was all rather straightforward to code up in Python as I could either use a package like PIL to read in the image sizes, or I could create an ImageStim in PsychoPy without specifying a size, and that would load the image in its original size. I could then query the .size property of the stimulus object to get the information I needed. I implemented the latter method, thinking that it would be compatible with PsychoJS because it didn’t require any external packages like PIL. However, I have since learned that PsychoJS apparently doesn’t allow you to create an ImageStim without specifying its size. Or at least, if you do so, the .size property will be left undefined.
Is there any way around this that will achieve the two goals I laid out at the start? Can PsychoJS load an image in its native size/aspect ratio? And if so, does it store the size information anywhere? Or is there some other way to read in image size in JS (or ideally, a method that works in Python and can be auto-translated to JS in PsychoPy)?
(I have considered hard-coding the image sizes into the script, but that would be a last resort as I may want to change the images in the future or add many more, so a flexible solution would be far preferable.)