@antmjs/vantui
Version:
一套适用于Taro3及React的vantui组件库
43 lines (42 loc) • 1.34 kB
JavaScript
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.rotateImage = rotateImage;
var _taro = require("@tarojs/taro");
function rotateImage(params) {
return new Promise(function (resove) {
var imageHeight = params.imageHeight,
imageWidth = params.imageWidth,
rotate = params.rotate,
ctx = params.ctx,
imagePath = params.imagePath,
canvasId = params.canvasId;
var canvasWidth, canvasHeight;
if (rotate === 90 || rotate === 270) {
canvasWidth = imageHeight;
canvasHeight = imageWidth;
} else {
canvasWidth = imageWidth;
canvasHeight = imageHeight;
}
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.translate(canvasWidth / 2, canvasHeight / 2);
ctx.rotate(rotate * Math.PI / 180);
ctx.drawImage(imagePath, -imageWidth / 2, -imageHeight / 2, imageWidth, imageHeight);
ctx.translate(-canvasWidth / 2, -canvasHeight / 2);
ctx.rotate(-rotate * Math.PI / 180);
ctx.draw(false, function () {
(0, _taro.canvasToTempFilePath)({
canvasId: canvasId,
success: function success(res) {
resove(res.tempFilePath);
},
fail: function fail(err) {
(0, _taro.hideLoading)();
console.error('rotateImage fail', err);
}
});
});
});
}
;