Skeleton of main loop and preparation to resize image