changed picture size calculation to have limits