How can I make a Driver expression access image RNA data through the image texture node?
Use self in drivers



Can use self in drivers, to see what is going on can make a driver method, register it, and print to system console what the value of self is, and often more importantly what self.id_data is.  

Here is a little test driver foo(self) that also returns a random number, so we can see if it is working, and when.

import bpy
from random import random

def foo(self):
    print(self, self.id_data)
    return random()

bpy.app.driver_namespace["foo"] = foo


Now add as a driver.

Add the driver directly into the property by typing #foo(self) before its a driver. Once it is a driver simply edit the expression in field. 



On first time, Make sure use self is checked, and update deps to fire it up.  If it breaks may have to update deps again.

For the simple driver will see that 

&lt;bpy_struct, NodeSocketVector("Vector")&gt; &lt;bpy_struct, ShaderNodeTree("Shader Nodetree")&gt;


is printed to sys console, and the driver is a random value.  Ok then self.id_data is the nodetree to which the texture node belongs.

Extending, will give a value of 4 if no image or no  node named "Image Texture" .. but if there is will return the image width.

import bpy

def foo(self):
    print(self, self.id_data)
    node_tree = self.id_data
    tn = node_tree.nodes.get("Image Texture")
    if tn:
        print(tn)
        if tn.image:
            return tn.image.size[0]
    else:
        print("NO IMAGE")
    return 4.0

bpy.app.driver_namespace["foo"] = foo


Could extend further by passing the name of the image texture node and image height or width as an int for instance, and not rely on it being called "Image Texture"

def foo(self, name="Image Texture", index=0, default=0.0):
    ...

        tn = node_tree.nodes.get(name)
        ...
            return tn.image.size[index]

    return default


Now can type #foo(self, "BarTexture", 1, -44) into a prop on nodetree and it will be the height of the image in the node named "BarTexture" or -44 if there is no image or no node.

Notes:

An issue is crossing an ID line in a path for a driver variable.  Starting from material going thru nodetree. If defined as a group then try using the nodetree ID type in a variable  (Haven't had much joy doing this).

Remove print statements if happy with result so you don't spam the console.