Skip to content

Commit

Permalink
Limit photo to 1500px
Browse files Browse the repository at this point in the history
  • Loading branch information
tcoupin committed Sep 21, 2019
1 parent 8d28da9 commit 2653468
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/js/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,51 +125,57 @@ function renderImage(src) {
}

var canvas = document.createElement("canvas");
canvas.width = image.width;
canvas.height = image.height;

var sx = vigiloconfig.IMAGE_MAX_SIZE / image.width;
var sy = vigiloconfig.IMAGE_MAX_SIZE / image.height;
var scale = Math.min(sx, sy);


canvas.width = image.width * scale;
canvas.height = image.height * scale;
var ctx = canvas.getContext("2d");
var x = 0;
var y = 0;
ctx.save();
if (orientation == 2) {
x = -canvas.width;
ctx.scale(-1, 1);
ctx.scale(-scale, scale);
} else if (orientation == 3) {
x = -canvas.width;
y = -canvas.height;
ctx.scale(-1, -1);
ctx.scale(-scale, -scale);
} else if (orientation == 4) {
y = -canvas.height;
ctx.scale(1, -1);
ctx.scale(scale, -scale);
} else if (orientation == 5) {
canvas.width = image.height;
canvas.height = image.width;
canvas.width = image.height * scale;
canvas.height = image.width * scale;
ctx.translate(canvas.width, canvas.height / canvas.width);
ctx.rotate(Math.PI / 2);
y = -canvas.width;
ctx.scale(1, -1);
ctx.scale(scale, -scale);
} else if (orientation == 6) {
canvas.width = image.height;
canvas.height = image.width;
canvas.width = image.height * scale;
canvas.height = image.width * scale;
ctx.translate(canvas.width, canvas.height / canvas.width);
ctx.rotate(Math.PI / 2);
} else if (orientation == 7) {
canvas.width = image.height;
canvas.height = image.width;
canvas.width = image.height * scale;
canvas.height = image.width * scale;
ctx.translate(canvas.width, canvas.height / canvas.width);
ctx.rotate(Math.PI / 2);
x = -canvas.height;
ctx.scale(-1, 1);
ctx.scale(-scale, scale);
} else if (orientation == 8) {
canvas.width = image.height;
canvas.height = image.width;
canvas.width = image.height * scale;
canvas.height = image.width * scale;
ctx.translate(canvas.width, canvas.height / canvas.width);
ctx.rotate(Math.PI / 2);
x = -canvas.height;
y = -canvas.width;
ctx.scale(-1, -1);
ctx.scale(-scale, -scale);
}
ctx.drawImage(image, x, y);
ctx.drawImage(image, 0, 0, image.width, image.height, x, y, canvas.width, canvas.height);
ctx.restore();
ctx.setTransform(1, 0, 0, 1, 0, 0);

Expand Down
2 changes: 2 additions & 0 deletions src/js/vigilo-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ var pkg= require('../../package.json');
export const VERSION = pkg.name+"-"+pkg.version;
export const VERSION_NUMBER = pkg.version;

export const IMAGE_MAX_SIZE=1500;

export function getInstance(){
var instance = localStorage.getItem('vigilo-instance');
if (instance == null){
Expand Down

0 comments on commit 2653468

Please sign in to comment.