How to keep image ratio while covering the highest portion of the screen?

If this template helps then use it. If not then just delete and start from scratch.

OS (Win 11):
PsychoPy version (2022.2.5):
Standard Standalone

Hello everyone, i am realizing an experiment where a subject look and evaluate different images. My problem is that these images are of different size and aspect ratio.
I use an image component inside a loop and I’ve tried to use a fixed size or to left the size blank so that the original one is used; in the first case the images are distorted and, in the second, the difference in size between images is too big and i am afraid this will influence the evaluation of the subjects.
1 - So i was wondering if there is a way to keep image ratio while covering the highest portion of the screen.
2 - I am pretty new to psychopy but i have intermediate knowledge in python programming language, so i take this opporunity to ask a side question: if i change some code in the codere and save the .psyexp file it will keep the changes made in the code without showing additional component in the builder?

Thanks to anyone who could help me.

  1. If you use height units and have a column in your spreadsheet called aspectRatio then you could use size [aspectRatio,1] for images with aspect ratios less than, say, 1.33 and [1.33,1.33/aspectRatio] for bigger values. You can calculate the aspect ratio of your screen on the fly if necessary.

  2. No, this doesn’t work. Changing the python file has no effect on the builder file. Add code components in Builder and add your custom code there.

We’re still working on implementing this in JS, but if you’re only running in python you can set one of the image dimensions to None to have it scale to keep aspect ratio with the other dimension. e.g. (200, None) means “200 wide, and as tall as it needs to be to keep the original aspect ratio”

1 Like

Thank you! I will try both solutions as soon as possible and i will let you know which works best for me.