To scale the image according to distance you can use Drivers applied to the Scale values of the Mapping node.
To add a Driver to a value just Right-Click on its field and select Add Driver option, or press Ctrl+D.
In the Driver Property panel :
use a Transfrom Channel type ( the one with the icon : (x) ) as the Driver variable,
set a reference object (mine is named Plane),
- set the type to one of the axes (here I set it to Z Location as the lamp is facing down on the Z axis),
- fine tune the effect in the Expression field. Here you are mapping the Z Location values to Scale values, so they need to be scaled down (0.2, moving the object 1 meter along Z axis will change the Scale by 0.2) and maybe inverted (-1) with particular positioning
Here are my results (bottom plane is the reference, watch the other two move and behave naturally) :
Notice how I can set the full image scale by moving the bottom plane (which was the Plane object reference in the Driver property panel), so it is similar to a real life situation when you are adjusting/setting the projector zoom to a background wall.