# Image Management Tool

**URL:** <https://forum.inductiveautomation.com/t/image-management-tool/37558>\
**Category:** Ignition\
**Created:** [August 10, 2020, 3:40pm UTC](https://forum.inductiveautomation.com/t/image-management-tool/37558 "2020-08-10T15:40:28Z")\
**Posts on this page:** 1\
**Showing post:** 19

<div class="post-metadata">

**Author:** ![mcgheeiv](https://avatars.discourse-cdn.com/v4/letter/m/71c47a/32.png) [@mcgheeiv](https://forum.inductiveautomation.com/u/mcgheeiv)\
**Post date:** [August 22, 2020, 9:23pm UTC](https://forum.inductiveautomation.com/t/image-management-tool/37558/19 "2020-08-22T21:23:58Z")

</div>

The following works in versin 7.9.13, but any suggestions for improvement are greatly appreciated:

Gateway Event Script \ Message named image\_upload:

```auto
	from com.inductiveautomation.ignition.gateway import SRContext
	from com.inductiveautomation.ignition.gateway.images import ImageFormat
	
	context = SRContext.get()
	image = context.getImageManager()

#	1 Valid image types PNG, JPEG, GIF, BMP
	image_type = {
		'PNG' : ImageFormat.PNG,
		'JPG' : ImageFormat.JPEG,
		'JPEG': ImageFormat.JPEG,
		'GIF' : ImageFormat.GIF,
		'BMP' : ImageFormat.BMP}[payload['image_type']]

	image.insertImage(payload['image_name'], payload['image_desc'], image_type, payload['folder'], payload['image_data'], payload['width'], payload['height'], payload['size'])
	
	return

```

Script on the “Upload” button on the Vision Window:

```auto
from java.awt import Toolkit
from java.io import File
from org.apache.commons.io import FilenameUtils
import imghdr

filepath = event.source.parent.getComponent('File Explorer').selectedPath

payload = {}
payload['image_name'] = File(filepath).name
payload['image_desc'] = None

# Valid image types PNG, JPEG, GIF, BMP, fix this in the message handler
payload['image_type'] = imghdr.what(str(filepath)).upper()

# Foward slash is necessary part of folder name
payload['folder'] = "folder/"

javaImage = Toolkit.getDefaultToolkit().getImage(filepath)
payload['width'] = javaImage.width
payload['height'] = javaImage.height

size = File(filepath).length()
payload['size'] = size

payload['image_data'] = system.file.readFileAsBytes(filepath)

# Call the gateway event script message handler, named image_upload on this project
proj = system.tag.read("[System]Client/System/ProjectName").value
status = system.util.sendRequest(proj, 'image_upload', payload)

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/image-management-tool/37558)._
