Save display/canvas as image
Hi,
I was wondering whether there is a different option than using the print button or an external tool/program to save the stimulus display created in OpenSesame to an image file? I am thinking of something similar to, for instance, pyplots savefig function, so that you can define properties like the format of the picture or maybe even dpi.
I tried what is suggested on psychopy forums:
win.getMovieFrame(buffer='back')
win.saveMovieFrames('stimuli.png')
...but that crashes with:
Traceback:
File "D:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\inline_script.py", line 102, in run
self.experiment.python_workspace._exec(self.crun)
File "D:\Program Files (x86)\OpenSesame\lib\site-packages\libopensesame\python_workspace.py", line 161, in _exec
exec(bytecode, self._globals)
File "", line 19, in
File "D:\Program Files (x86)\OpenSesame\lib\site-packages\psychopy\visual\window.py", line 798, in getMovieFrame
im = self._getFrame(buffer=buffer)
File "D:\Program Files (x86)\OpenSesame\lib\site-packages\psychopy\visual\window.py", line 820, in _getFrame
im = Image.fromstring(mode='RGBA', size=self.size, data=bufferDat)
File "D:\Program Files (x86)\OpenSesame\lib\site-packages\PIL\Image.py", line 2077, in fromstring
"Please call frombytes() instead.")
Exception: fromstring() has been removed. Please call frombytes() instead.
I assume some critical module is not up-to-date (I was running the script on the psychopy backend)?
Is there maybe another alternative?
Thanks,
Michel
Comments
Hi Michel,
Wouldn't it suffice to just log all the parameters that determine what the screen will look like?
If not, then there's python code to just save a printscreen to a file, see for instance this topic on another forum: http://stackoverflow.com/questions/17832717/python-auto-save-printscreen
You could place similar code in an inline script, placed right after your sketchpad for instance.
Cheers
Josh
Making a canvas function (a la
canvas.save()
) is also on our to-do list. However, it is not finished yet. Daniel started to implement this. Maybe the current version is already useful to you:https://github.com/smathot/OpenSesame/issues/318
Eduard
Thanks for pointing that out Eduard. I indeed started working on such a function, but never got around to really implementing it. The example function should provide a good start and should work out of the box, although newer versions of OS might have some changes that break the function.