resize to input dimensions when formatting in python