function Base() { }
Base.prototype.myFunction = function (img, tag_width, tag_height, pt, pl) {
  var x = document.createElement("CANVAS");
  x.width = tag_width;
  x.height = tag_height;
  var ctx = x.getContext("2d");
  var pt = pt,
    pl = pl;
  if (pt === "center" || pl === "center") {
    pt = (img.height - tag_height) / 2;
    pl = (img.width - tag_width) / 2;
    ctx.drawImage(img, -pl, -pt, img.width, img.height);
  } else {
    ctx.drawImage(img, -pl, -pt, img.width, img.height);
  }
  return x;
};
Base.prototype.set_img = function (img, target_width, target_height) {
  var old_img_width = img.width;
  var old_img_height = img.height;
  var img_ratio = img.width / img.height;
  var target_ratio = target_width / target_height;
  if (target_ratio > img_ratio) {
    img.width = img.width * (target_width / old_img_width);
    img.height = img.height * (target_width / old_img_width);
  } else {
    img.width = img.width * (target_height / old_img_height);
    img.height = img.height * (target_height / old_img_height);
  }
  return img;
};
Base.prototype.creatImage = function (imgUrl) {
  var img = document.createElement("img");
  // img.setAttribute("crossOrigin",'Anonymous')
  img.src = imgUrl;
  return img;
};
Base.prototype.cutImg = function (
  imgUrl,
  target_width,
  target_height,
  pt,
  pl,
  callback
) {
  var img = this.creatImage(imgUrl);
  img.onload = function () {
    img = Base.prototype.set_img(img, target_width, target_height, pt, pl);
    callback(
      Base.prototype.myFunction(img, target_width, target_height, pt, pl)
    );
  };
};
