24. image — Saving OpenGL renderings to image files. — pyFormex v0.8.6 documentation

### Navigation

- index
- modules |
- next |
- previous |
- pyFormex v0.8.6 documentation >
- pyFormex reference manual >

# 24. `image` — Saving OpenGL renderings to image files.

This module defines some functions that can be used to save the OpenGL rendering and the pyFormex GUI to image files. There are even provisions for automatic saving to a series of files and creating a movie from these images.

`Classes defined in module image`

`Functions defined in module image`

`image.` `initialize`()

  Initialize the image module.

`image.` `imageFormats`()

  Return a list of the valid image formats.

  image formats are lower case strings as ‘png’, ‘gif’, ‘ppm’, ‘eps’, etc. The available image formats are derived from the installed software.

`image.` `checkImageFormat`(fmt, verbose=False)

  Checks image format; if verbose, warn if it is not.

  Returns the image format, or None if it is not OK.

`image.` `imageFormatFromExt`(ext)

  Determine the image format from an extension.

  The extension may or may not have an initial dot and may be in upper or lower case. The format is equal to the extension characters in lower case. If the supplied extension is empty, the default format ‘png’ is returned.

`image.` `save_canvas`(canvas, fn, fmt='png', quality=-1, size=None)

  Save the rendering on canvas as an image file.

  canvas specifies the qtcanvas rendering window. fn is the name of the file fmt is the image file format

`image.` `save_window`(filename, format, quality=-1, windowname=None)

  Save a window as an image file.

  This function needs a filename AND format. If a window is specified, the named window is saved. Else, the main pyFormex window is saved.

`image.` `save_main_window`(filename, format, quality=-1, border=False)

  Save the main pyFormex window as an image file.

  This function needs a filename AND format. This is an alternative for save_window, by grabbin it from the root window, using save_rect. This allows us to grab the border as well.

`image.` `save_rect`(x, y, w, h, filename, format, quality=-1)

  Save a rectangular part of the screen to a an image file.

`image.` `save`(filename=None, window=False, multi=False, hotkey=True, autosave=False, border=False, rootcrop=False, format=None, quality=-1, size=None, verbose=False)

  Saves an image to file or Starts/stops multisave mode.

  With a filename and multi==False (default), the current viewport rendering is saved to the named file.

  With a filename and multi==True, multisave mode is started. Without a filename, multisave mode is turned off. Two subsequent calls starting multisave mode without an intermediate call to turn it off, do not cause an error. The first multisave mode will implicitely be ended before starting the second.

  In multisave mode, each call to saveNext() will save an image to the next generated file name. Filenames are generated by incrementing a numeric part of the name. If the supplied filename (after removing the extension) has a trailing numeric part, subsequent images will be numbered continuing from this number. Otherwise a numeric part ‘-000’ will be added to the filename.

  If window is True, the full pyFormex window is saved. If window and border are True, the window decorations will be included. If window is False, only the current canvas viewport is saved.

  If hotkey is True, a new image will be saved by hitting the ‘S’ key. If autosave is True, a new image will be saved on each execution of the ‘draw’ function. If neither hotkey nor autosave are True, images can only be saved by executing the saveNext() function from a script.

  If no format is specified, it is derived from the filename extension. fmt should be one of the valid formats as returned by imageFormats()

  If verbose=True, error/warnings are activated. This is usually done when this function is called from the GUI.

`image.` `saveImage`(filename=None, window=False, multi=False, hotkey=True, autosave=False, border=False, rootcrop=False, format=None, quality=-1, size=None, verbose=False)

  Saves an image to file or Starts/stops multisave mode.

  With a filename and multi==False (default), the current viewport rendering is saved to the named file.

  With a filename and multi==True, multisave mode is started. Without a filename, multisave mode is turned off. Two subsequent calls starting multisave mode without an intermediate call to turn it off, do not cause an error. The first multisave mode will implicitely be ended before starting the second.

  In multisave mode, each call to saveNext() will save an image to the next generated file name. Filenames are generated by incrementing a numeric part of the name. If the supplied filename (after removing the extension) has a trailing numeric part, subsequent images will be numbered continuing from this number. Otherwise a numeric part ‘-000’ will be added to the filename.

  If window is True, the full pyFormex window is saved. If window and border are True, the window decorations will be included. If window is False, only the current canvas viewport is saved.

  If hotkey is True, a new image will be saved by hitting the ‘S’ key. If autosave is True, a new image will be saved on each execution of the ‘draw’ function. If neither hotkey nor autosave are True, images can only be saved by executing the saveNext() function from a script.

  If no format is specified, it is derived from the filename extension. fmt should be one of the valid formats as returned by imageFormats()

  If verbose=True, error/warnings are activated. This is usually done when this function is called from the GUI.

`image.` `saveNext`()

  In multisave mode, saves the next image.

  This is a quiet function that does nothing if multisave was not activated. It can thus safely be called on regular places in scripts where one would like to have a saved image and then either activate the multisave mode or not.

`image.` `saveIcon`(fn, size=32)

  Save the current rendering as an icon.

`image.` `autoSaveOn`()

  Returns True if autosave multisave mode is currently on.

  Use this function instead of directly accessing the autosave variable.

`image.` `createMovie`(encoder='ffmpeg')

  Create a movie from a saved sequence of images.

  encoder is one of: ‘ffmpeg, mencoder, convert’

`image.` `saveMovie`(filename, format, windowname=None)

  Create a movie from the pyFormex window.

### Navigation

- index
- modules |
- next |
- previous |
- pyFormex v0.8.6 documentation >
- pyFormex reference manual >