spss.GetImage Function (Python)

spss.GetImage(handle,imagename). Retrieves an image associated with an output XPath DOM. The argument handle specifies the particular XPath DOM and must be a valid handle name defined by a previous IBM® SPSS® Statistics   OMS command. The argument imagename is the filename associated with the image in the OXML output--specifically, the value of the imageFile attribute of the chart, modelView or treeView element associated with the image.

The returned value is a tuple with 3 elements. The first element is the binary image. The second element is the amount of memory required for the image. The third element is a string specifying the image type: “PNG”, “JPG”, “BMP”.

Example

OMS
  /SELECT CHARTS
  /IF COMMANDS=['Frequencies']
  /DESTINATION FORMAT=OXML IMAGES=YES 
   CHARTFORMAT=IMAGE IMAGEROOT='myimages' IMAGEFORMAT=JPG XMLWORKSPACE='demo'.

FREQUENCIES VARIABLES=jobcat
  /BARCHART PERCENT
  /ORDER=ANALYSIS.

OMSEND.

BEGIN PROGRAM.
import spss
imagename=spss.EvaluateXPath('demo','/outputTree',
 '//command[@command="Frequencies"]/chartTitle[@text="Bar Chart"]/chart/@imageFile')[0]
image = spss.GetImage('demo',imagename)
f = file('/temp/myimage.jpg','wb')
f.truncate(image[1])
f.write(image[0])
f.close()
spss.DeleteXPathHandle('demo')
END PROGRAM.
  • The OMS command routes output from the FREQUENCIES command to an output XPath DOM with the handle name of demo.
  • To route images along with the OXML output, the IMAGES keyword on the DESTINATION subcommand (of the OMS command) must be set to YES, and the CHARTFORMAT, MODELFORMAT, or TREEFORMAT keyword must be set to IMAGE.
  • The spss.EvaluateXPath function is used to retrieve the name of the image associated with the bar chart output from the FREQUENCIES command. In the present example, the value returned by spss.EvaluateXPath is a list with a single element, which is then stored to the variable imagename.
  • The spss.GetImage function retrieves the image, which is then written to an external file.