图片等比例缩放的计算公式

等比列计算公式:
百分比缩放
const imgPect = (picture_width, picture_height, default_width, default_height) => {
  var widthRatio = default_width / picture_width
  var heightRatio = default_height / picture_height
  var ratio 
  widthRatio < heightRatio ? ratio = widthRatio : ratio = heightRatio
  var currentImg = { picture_width: parseInt(picture_width * ratio), picture_height: parseInt(picture_height * ratio)}
  return currentImg
}

 

posted @ 2018-12-25 10:33  10后程序员劝退师  阅读(6647)  评论(0)    收藏  举报