So, to find the area of the frame, we find the area of the entire thing and subtract the area of the painting.
Ap = w(w + 5) = w2 + 5w
Now, if the border is 2 inches all the way around, it adds 4 inches to both the length and the width. You should be able to see that in your sketch.
Ae = (w + 4)(w + 9) = w2 + 13w + 36
Af = w2 + 13w + 36 - (w2 + 5w) = 8w + 36
The perimeter of the frame is the distance around the outside.
Pf = 2(w + 4) + 2(w + 9) = 2w + 8 + 2w + 18 = 4w + 26