Working image resizing code