Let's the first rectangle has coordinates of two (diagonal opposite) corners:
(X0_Old, Y0_Old) and (X1_Old, Y1_Old)
and the second one coordinates are:
(X0_New, Y0_New) and (X1_New, Y1_New)
then coordinate transformation will look like
for every point:
X_New = X0_New + (X_Old - X0_Old) * X_Coeff
where
X_Coeff = (X1_New - X0_New) / (X1_Old - X0_Old)
(and the same for Y-coordinates)