Context.area
returns the area in context (and its attributes). Test using the python console:
>>> C.area
bpy.data.screens['Scripting']...Area
>>> C.area.
as_pointer(
bl_rna
bl_rna_get_subclass(
...
>>> C.area.type
'CONSOLE'
Get the active space of the Image Editor and use SpaceImageEditor.image
(in this case the same for all spaces). Example based on the Operator Simple template. Run the script, in the Image Editor press F3 and type "Simple Image..."
:
import bpy
class SimpleOperator(bpy.types.Operator):
"""Tooltip"""
bl_idname = "image.simple_operator"
bl_label = "Simple Image Editor Operator"
@classmethod
def poll(cls, context):
return context.area.type == 'IMAGE_EDITOR'
def execute(self, context):
image = context.area.spaces.active.image
if image:
# print (dir(image)) # Print all image attributes
self.report({'INFO'}, "{}, {}".format(image.name, image.filepath))
else:
self.report({'INFO'}, "No active image")
return {'FINISHED'}
def register():
bpy.utils.register_class(SimpleOperator)
def unregister():
bpy.utils.unregister_class(SimpleOperator)
if __name__ == "__main__":
register()
Related: Active image of UV/Image Editor