Fix #513 by correctly tracking width and height resize ratios