# How to use icon previews from bpy.data.images?

I want to use the template_icon_view to display a set of images from bpy.data.images. I know there is bpy.utils.preview which has a load function to load in external images. Is it possible to feed a template_icon_view with internal images?

What would be the proper approach to create an enum property with the images?

• Actually, I asked that two weeks ago, here's the answer: blender.stackexchange.com/questions/47504/… Mar 9 '16 at 1:10
• Hi Ray, yes.. I have seen this question. My problem is that this thumbnails are generate of external images. I want to use internal images that are not stored somewhere on the harddrive. The bpy.tils.preview module needs external images to generate that previews.
– ndee
Mar 9 '16 at 6:23

Data-blocks store their own previews, so you can access bpy.types.ImagePreview.icon_id

The icon_id can be passed to UI elements that take an icon value.

eg:

import bpy
for image in bpy.data.images:
print(image.name, image.preview.icon_id)


One area I'd need to look into is how to generate icons from images. The interface does this automatically, but you may want to generate the images on demand (as far as I can see we don't have a direct API call to do this).

Heres a fully working example of using image previews in Blender's interface.

# Run this script and check the object properties.
import bpy

class ImagePreviewPanel(bpy.types.Panel):
bl_label = "Image Icons"
bl_idname = "OBJECT_PT_image_icons"
bl_space_type = 'PROPERTIES'
bl_region_type = 'WINDOW'
bl_context = "object"

def draw(self, context):
layout = self.layout
for image in bpy.data.images:
layout.label(image.name, icon_value=image.preview.icon_id)
if not bpy.data.images:
layout.label("No images!")

def register():
bpy.utils.register_class(ImagePreviewPanel)

def unregister():
bpy.utils.unregister_class(ImagePreviewPanel)

if __name__ == "__main__":
register()

• It seems I have exactly that problem. I get the icon id and the template_icon_view generates the items based on the created enum. But the icons are empty.
– ndee
Mar 9 '16 at 6:59
• The icons should work in enums too, if you have issues here could be different question. Mar 9 '16 at 7:20
• I have a question concerning the part how to generate icons from images. Is there a way to manually trigger an icon to be generated?
– ndee
Jul 11 '16 at 20:56
• Unfortunately this method that I find quite obvious and right, does not always generate a preview, it probably depends on the format and size of the image. The blender itself does not seem to generate previews of such images, it seems to happen on some png images in 2k. I think it's a bug or if it's not it creates big problems. Feb 25 at 13:50