Export Images Using Scripting

I have been using some of the javadocs that ignition provides to add more functionality to my ignition projects such as importing and exporting images on the client side. I currently have the importing of images working fine but I am stuck trying to get images to export correctly from the client side.

How I am currently doing this is using a gateway message in order for me to grab Igniton gateway context. Once I grab context I get the image manager and use the getImage method to get the image. This then returns me a ImageRecord object that I have to go and grab the BlobData, width, height, etc. from.

From there I know that I have to extract the value from the TypeField object types that Ignition has. This is where it is giving me an issue. No matter how I try to extract this data, it always gives me either a value / type of None or it gives me an array(‘b’) in the case of the BlobField type. I have tried a bunch of different ways to try to get this working using variables and methods that these

My code is as follows. Please let me know what I am missing in order to extract the images from the internal database.

	from com.inductiveautomation.ignition.gateway import IgnitionGateway
	from com.inductiveautomation.ignition.gateway.images import ImageRecord
	from com.inductiveautomation.ignition.gateway.localdb.persistence import StringField
	from com.inductiveautomation.ignition.gateway.localdb.persistence import IntField
	from com.inductiveautomation.ignition.gateway.images import ImageFormat

	context = IgnitionGateway.get()
	image = context.getImageManager()
		
	imageData = image.getImage(payload['path'])
	system.util.getLogger("get_Image log").infof("after getImage function: %s", str(imageData))
	data= imageData.Data
	default = imageData.Data.getDefault()
	system.util.getLogger("get_Image log").infof("after getImage function: %s", str(data))
	system.util.getLogger("get_Image log").infof("after getImage function: %s", str(type(data)))

	system.util.getLogger("get_Image log").infof("after getImage function: %s", str(default))
	system.util.getLogger("get_Image log").infof("after getImage function: %s", str(type(default)))

	test = {"data":default,
			'description':'',
			'height':'',
			'path':'',
			'width':''}

The logs that go with this script. (oldest logs first)

after getImage function: [ImageRecord folsom.png]
after getImage function: [F ImageRecord.Width]
after getImage function: <type 'com.inductiveautomation.ignition.gateway.localdb.persistence.IntField'>
after getImage function: None
after getImage function: <type 'NoneType'>
1 Like

I think you want to do something like this:

imageBytes = imageData.getBytes(ImageRecord.Data)

This should give you a byte array, which it sounds like in one attempt you already had (array(‘b’)), which is the only thing I can imagine you’d want.

2 Likes

That was the fix. Thank you.