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
Initialize the image module.
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.
Checks image format; if verbose, warn if it is not.
Returns the image format, or None if it is not OK.
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.
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
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.
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.
Save a rectangular part of the screen to a an image file.
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.
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.
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.
Changes the background color of an .xpm image.
This changes the background color of an .xpm image to the given value. fn is the filename of an .xpm image. color is a string with the new background color, e.g. in web format (‘#FFF’ or ‘#FFFFFF’ is white). A special value ‘None’ may be used to set a transparent background. The current background color is selected from the lower left pixel.
Save the current rendering as an icon.
Returns True if autosave multisave mode is currently on.
Use this function instead of directly accessing the autosave variable.
Create a movie from a saved sequence of images.
Parameters:
Other parameters may be passed and may be needed, depending on the converter program used. Thus, for the default ‘convert’ program, each extra keyword parameter will be translated to an option ‘-keyword value’ for the command.
Example:
createMovie('images*.png',delay=1,colors=256)
will create an animated gif ‘output.gif’.
Create a movie from the pyFormex window.