fix loop var
added conditions to define if image is within border limits.
define what happens if image is within border