fix image cropping js algorithm