for reference,
image_objs = []
for i in range(0,n): #number of row
#select only current ower rows in database
result = app_tables.biofilm_images.search(
owner=anvil.server.get_session_id(),
)[i]
row = i+1
image_objs.append(anvil.media.TempFile(result['original_image']))
image_objs.append(anvil.media.TempFile(result['gray_image']))
image_objs.append(anvil.media.TempFile(result['gray_image_filtered']))
image_objs.append(anvil.media.TempFile(result['bw_image']))
image_objs.append(anvil.media.TempFile(result['bw_image_filtered']))
print(image_objs) yields...
[<anvil.media.TempFile object at 0x7fa577e4a710>, <anvil.media.TempFile object at 0x7fa577e4ab90>, <anvil.media.TempFile object at 0x7fa53d743890>, <anvil.media.TempFile object at 0x7fa53d743ad0>, <anvil.media.TempFile object at 0x7fa53d743850>]
Thanks Ian, but when I run
print(image_objs[0].get_bytes())
alone I get the same error “AttributeError: ‘TempFile’ object has no attribute ‘get_bytes’”
edit: I was able to get a list of lazy media objects by removing the anvil.media.TempFile from the above for loop, so
image_objs is now
[<anvil._server.LazyMedia object at 0x7fbfdc690890>, <anvil._server.LazyMedia object at 0x7fbfdc6907d0>, <anvil._server.LazyMedia object at 0x7fbfdc690850>, <anvil._server.LazyMedia object at 0x7fbfdc690790>, <anvil._server.LazyMedia object at 0x7fbfdc690810>]
update:
So I got xlfswriter to take the data doing this:
image_data = image_objs[0].get_bytes()
worksheet.insert_image(row,3,'image1', {"image_data": image_data, 'x_offset': 5, 'y_offset': 5, 'positioning': 1})
But when it gets to workbook.close(), I get this error, “AttributeError: ‘bytes’ object has no attribute ‘getvalue’”
update2: looks like the data might have to be a BytesIO object, not the data itself.
update3:
Was able to get it working with what Ian suggested, thanks again!
for i in range(0,n): #number of row
#select only current ower rows in database
result = app_tables.biofilm_images.search(
owner=anvil.server.get_session_id(),
)[i]
row = i+1
for j in range(0,5):
image_data = image_objs[i*5+j].get_bytes()
data = io.BytesIO(image_data)
worksheet.insert_image(row,2+j,'image'+str(i)+str(j), {"image_data": data, 'x_offset': 5, 'y_offset': 5, 'positioning': 1})