# Min and Max Image Zoom

**URL:** <https://discourse.psychopy.org/t/min-and-max-image-zoom/9345>\
**Category:** Builder\
**Created:** [October 9, 2019, 9:19am UTC](https://discourse.psychopy.org/t/min-and-max-image-zoom/9345 "2019-10-09T09:19:08Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![agboard1](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@agboard1](https://discourse.psychopy.org/u/agboard1)\
**Post date:** [October 9, 2019, 9:19am UTC](https://discourse.psychopy.org/t/min-and-max-image-zoom/9345/1 "2019-10-09T09:19:08Z")

</div>

OS: Mojave  
Version: 3.0.0b11

I am running an experiment that requires participants to zoom in and out of images (circular) using a keyboard response (either left or right). I am trying to put a min and max threshold on their responses (in relation to the image size) so they can only zoom in or out of the image to a certain image size e.g. 1600,1600 pixels. However, I would like them to be able to zoom in the other direction if they meet the max or min threshold either end (I hope this makes sense).

I have declared min and max image size in the ‘Begin Routine’ section of a code snippet and have attempted to call these in, however they don’t seem to limit the size of the image. I have tried other variations where I say if maxSize is reached then stop keyboard input but this ends the routine, and I want the participant to be able to scale up and down until they are happy with the image size then finish the routine (trial) themselves.

maxSize = (1600,1600)  
minSize = (1200,1200)

Below is the code to zoom in and out (in pixels). I have tried to declare the max and min sizes after the key inputs.

```auto
if response_image.status == STARTED:    
    key = event.getKeys() 
    if len(key) > 0:         
        if key[0] == 'left':     
            response_image.size += (-100,-100)
            response_image.size == maxSize 

        elif key[0] == 'right':     
            response_image.size += (100,100)
            response_image.size == minSize

        elif key[0] == 'space':     
            thisExp.addData('chosen_size', response_image.size)               
            thisExp.addData('RT', t)               
            continueRoutine = False         
        elif key[0] == 'q':     
            win.close()     
            core.quit()  

keys = event.getKeys(keyList = ['q']) 
if 'q' in keys:         
    win.close()         
    core.quit()  
event.clearEvents(eventType = 'keyboard')

```

Thank you for your help.

---

<div class="post-metadata">

**Author:** ![dvbridges](https://sea2.discourse-cdn.com/flex002/user_avatar/discourse.psychopy.org/dvbridges/32/1918_2.png) [@dvbridges](https://discourse.psychopy.org/u/dvbridges)\
**Post date:** [October 9, 2019, 1:27pm UTC](https://discourse.psychopy.org/t/min-and-max-image-zoom/9345/2 "2019-10-09T13:27:51Z")

</div>

Hi @agboard1 , you just need to add an extra condition so that the size changes only when the image is larger or smaller / equal to the min/max:

```auto
# Begin Experiment
maxSize = 1600
minSize = 1200

if response_image.status == STARTED:    
    key = event.getKeys() 
    if len(key) > 0:         
        if key[0] == 'left' and response_image.size[0] >= minSize:     
            response_image.size += (-100,-100)
            response_image.size == maxSize 

        elif key[0] == 'right' and response_image.size[0] <= maxSize:       
            response_image.size += (100,100)
            response_image.size == minSize

#... etc

```

---

<div class="post-metadata">

**Author:** ![agboard1](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@agboard1](https://discourse.psychopy.org/u/agboard1)\
**Post date:** [October 10, 2019, 3:58pm UTC](https://discourse.psychopy.org/t/min-and-max-image-zoom/9345/3 "2019-10-10T15:58:33Z")

</div>

Thank you.
