Estoy revisando un angularJS
código antiguo escrito por desarrolladores anteriores, y encontré uno if statement
que verifica si la imagen tiene un tamaño de 1: 1 o 16/4 o 4/3 y, en caso afirmativo, se puede cargar la imagen.
Sin embargo, cuando trato de cargar una imagen en 16/4 o 4/3, simplemente se niega a cargar, como si no estuviera en el si. Solo funciona la relación 1:1.
Mi pregunta es ¿cómo podría reescribir el código para que funcione?
$scope.$watch('file', function (val) {
if (val != undefined) {
if (!val[0].isImage) {
$scope.errorMsg = 'It must be an image';
$scope.disabled = true;
}
// This is the if that doesn't work well
let ratio = Math.ceil(val[0].width / val[0].height);
if (ratio == 16 / 9 || ratio == 4 / 3 || ratio == 1) {
$scope.errorMsg = '';
$scope.disabled = false;
$scope.saveFile();
} else {
$scope.errorMsg = 'Your selected image must have the given ratio. (16:9 or 4:3 or 1:1)';
$scope.disabled = true;
}
}
});
Si usted tiene alguna pregunta no dude en preguntar.