| Reference | Downloads | Github

Display different sizes images

Hello everyone,

I’m working on a simple image presentation experiment. However, all the images I received to display are quite different sizes. I’d like to get them to display as full screen as possible, with no cropping. That is, it will always scale until it hits a border (e.g. wide images will have extra borders only at the top, and high images will have borders on the sides).

How could I check the size of the image before loading it with ImageStim and only scale to the ratio of the screen size and image size on its longest dimension?

Thanks for the help and advice!

Hello Mensen,

Just to clarify, you would like to have the image take up as much screen space as possible while maintaining its aspect ratio?

That’s a much better way to phrase what I had said :slight_smile:

It looks like you’d need to import PIL, load the image, retrieve the height and width values, divide this by the screen size and then use the product of this and the screen size as your size variable in your imageStim… might be easier to just resize the images so they are a standard size!

Hi Mensen,

if you use imageStim to open the image from the file without using the size parameter, then the value inside the variable size is from your image. So for myImage it is myImage.size and is a list with the x and y values. You can then use that info to change the size to what you need. Hope this helps.


Oh yeah! the API doc says none makes the size default which I took to mean (0.5,0.5) - native size for this makes much more sense