Image manager - storing images dynamically


	from javax.imageio import ImageIO
	from java.io import ByteArrayInputStream
	from com.inductiveautomation.ignition.gateway.images import ImageManager, ImageFormat
	from com.inductiveautomation.ignition.gateway import IgnitionGateway

	# Obtain the GatewayContext
	gatewayContext = IgnitionGateway.get()
	# Get the ImageManager
	imageManager = gatewayContext.getImageManager()
	
	imageBytes = event.file.getBytes()
	# Convert the image bytes to a ByteArrayInputStream
	byte_stream = ByteArrayInputStream(imageBytes)
	# Use ImageIO to read the image from the byte stream
	buffered_image = ImageIO.read(byte_stream)
	
	# Get the width and height of the image
	width = buffered_image.getWidth()
	height = buffered_image.getHeight()
	# Other Variables
	Name = event.file.name
	Description = event.file.name
	Imagetype = ImageFormat.PNG
	directory = ''
	#ImageType = event.file.name.split('.')[-1].upper()
	inputfile = imageBytes
	size = len(inputfile)
	
	#Upload to image manager
	imageManager.insertImage(Name,Description,Imagetype,directory,inputfile,width,height,size)
	
	
	

I wrote this code it goes directly into the file upload component this was a fast mock up so if you want security and verification I would add a button that runs this script.

Here is the example in use:

ShowingImageUpload

It also directly uploads to the image management tool in Ignition
image

2 Likes