expo-image-manipulator
Version:
Provides functions that let you manipulation images on the local file system, eg: resize, crop.
34 lines (32 loc) • 1.06 kB
JavaScript
import { getContext } from '../utils.web';
function sizeFromAngle(width, height, angle) {
const radians = angle * Math.PI / 180;
let c = Math.cos(radians);
let s = Math.sin(radians);
if (s < 0) {
s = -s;
}
if (c < 0) {
c = -c;
}
return {
width: height * s + width * c,
height: height * c + width * s
};
}
export default ((canvas, degrees)=>{
const { width, height } = sizeFromAngle(canvas.width, canvas.height, degrees);
const result = document.createElement('canvas');
result.width = width;
result.height = height;
const context = getContext(result);
// Set the origin to the center of the image
context.translate(result.width / 2, result.height / 2);
// Rotate the canvas around the origin
const radians = degrees * Math.PI / 180;
context.rotate(radians);
// Draw the image
context.drawImage(canvas, -canvas.width / 2, -canvas.height / 2, canvas.width, canvas.height);
return result;
});
//# sourceMappingURL=RotateAction.web.js.map