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
OMScommand routes output from theFREQUENCIEScommand to an output XPath DOM with the handle name of demo. - To route images along with the OXML output, the
IMAGESkeyword on theDESTINATIONsubcommand (of theOMScommand) must be set toYES, and theCHARTFORMAT,MODELFORMAT, orTREEFORMATkeyword must be set toIMAGE. - The
spss.EvaluateXPathfunction is used to retrieve the name of the image associated with the bar chart output from theFREQUENCIEScommand. In the present example, the value returned byspss.EvaluateXPathis a list with a single element, which is then stored to the variable imagename. - The
spss.GetImagefunction retrieves the image, which is then written to an external file.