Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Supported by

Resize the x-axis of an image

Dear all,


for an experiment I need to show an image, but whose x- and y-axis are scaled with different values (i.e. y-axis scale = 1, x-axis scale = 2).

Is it possible to do this in opensesame?

I have tried to see if it is possible with Canvas, but it seems that there is not this possibility.


Thanks a lot for your support,


Michele

Comments

  • Hi @michelescandola ,

    To do this, you'd need some Python script, but nothing too complicated. The script below, which you would put in the prepare phase of an inline_script that precedes the sketchpad in which you actually use the image, shows the basic idea.

    You first read an image from the file pool (SRC ), then you resize it to the target dimensions, and then you save it as a new image, again in the file pool (DST ), which you can subsequently use in a sketchpad . Does that make sense?

    -- Sebastiaan

    import os
    from PIL import Image
    
    SRC = 'tmp.jpg'
    DST = 'tmp2.jpg'
    TARGET_WIDTH = 200
    TARGET_HEIGHT = 400
    
    im = Image.open(pool[SRC])
    im = im.resize((TARGET_WIDTH, TARGET_HEIGHT))
    im.save(os.path.join(pool.folder(), DST))
    
  • Dear Sebastiaan,

    thanks a lot.

    Probably this is not the most elegant solution ever thought, but it works!

    Enjoy your coffee!

Sign In or Register to comment.