code: function scale(img, max, oWidth, oHeight) {
          var width = 0, height = 0, percent, ow = img.width || oWidth, oh = img.height || oHeight;
          if (ow > max || oh > max) {
              if (ow >= oh) {
                  if (width = ow - max) {
                      percent = (width / ow).toFixed(2);
                      img.height = oh - oh * percent;
                      img.width = max;
                  }
              } else {
                  if (height = oh - max) {
                      percent = (height / oh).toFixed(2);
                      img.width = ow - ow * percent;
                      img.height = max;
                  }
              }
          }
      }
docs: 图片缩放