# Updating Image component based off of newest image in a directory

**URL:** <https://forum.inductiveautomation.com/t/updating-image-component-based-off-of-newest-image-in-a-directory/14972>\
**Category:** Ignition\
**Tags:** ignition79, scripting\
**Created:** [August 2, 2017, 9:24pm UTC](https://forum.inductiveautomation.com/t/updating-image-component-based-off-of-newest-image-in-a-directory/14972 "2017-08-02T21:24:04Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 7, 2017, 9:36pm UTC](https://forum.inductiveautomation.com/t/updating-image-component-based-off-of-newest-image-in-a-directory/14972/7 "2017-08-07T21:36:43Z")

</div>

Here’s some code to display an image, scaled, on the paintable canvas. Also caches the read image to avoid a little bit of extra load:

```auto
g = event.graphics
filename = r"path/to/file.png"

cachedName = event.source.getClientProperty("img-bytes-cached-name")
bytes = event.source.getClientProperty("img-bytes-cached")
if filename!=cachedName or not bytes:
	# Image not cached - load from database
	#bytes = system.db.runScalarQuery("SELECT data FROM image_test WHERE imgname='%s'"%name)
	bytes = system.file.readFileAsBytes(filename)
	event.source.putClientProperty("img-bytes-cached",bytes)
	event.source.putClientProperty("img-bytes-cached-name",filename)

if bytes:
	from javax.imageio import ImageIO
	from java.io import ByteArrayInputStream
#	from java.awt.geom import AffineTransform
#	scale = AffineTransform()
	image = ImageIO.read(ByteArrayInputStream(bytes))
	
	g.drawImage(image, 0, 0, event.width, event.height, event.source)

```

---

_[View the full topic](https://forum.inductiveautomation.com/t/updating-image-component-based-off-of-newest-image-in-a-directory/14972)._
