(1) adjust the width calculation algorithm
(2) add the output image resolution control and fix the image sizes