Resize algorithm. Upd. border drawing algorithm.