  We present a general framework for matching the point-spread function (PSF),
photometric scaling, and sky background between two images, a subject which is
commonly referred to as difference image analysis (DIA). We introduce the new
concept of a spatially varying photometric scale factor which will be important
for DIA applied to wide-field imaging data in order to adapt to transparency
and airmass variations across the field-of-view. Furthermore, we demonstrate
how to separately control the degree of spatial variation of each kernel basis
function, the photometric scale factor, and the differential sky background. We
discuss the common choices for kernel basis functions within our framework, and
we introduce the mixed-resolution delta basis functions to address the problem
of the size of the least-squares problem to be solved when using delta basis
functions. We validate and demonstrate our algorithm on simulated and real
data. We also describe a number of useful optimisations that may be capitalised
on during the construction of the least-squares matrix and which have not been
reported previously. We pay special attention to presenting a clear notation
for the DIA equations which are set out in a way that will hopefully encourage
developers to tackle the implementation of DIA software.
