I have the following code that grabs the dimensions of the resulting image from a cropper tool, and based on the result of dividing height/width, generates a value which is used as the image aspect ratio. I then have this value inserted into the query string url: urlLocation + imageid.value + "/orientation/" + orientation + "/image/" + saveImage,
. The issue is that the logic to find the image ratio is not operating correctly, and is seeing all images cropped(whether they are square(height = width), portrait or landscape) as "SQUARE".
$submitButton = $('<div class="btn btn-success submit"></div>')
.text('Submit ' + imageid.value).appendTo($(".submit-well"))
.on('click', function () {
//var USERNAME = "bob";
//var PASSWORD = "bobpass";
var urlLocation = "http://www.url.com/rest/v1/cms/story/";
var saveImage = encodeURIComponent(dataUrl);
//USED IF ORIENTATION HAS TO BE MANUALLY SELECTED
//var orientation = $("#orientation").val();
//
var resultHeight = $("#result").height();
var resultWidth = $("#result").width();
var divide = resultHeight / resultWidth;
var precision = divide.toFixed(1);
if (precision == 1.77) {
orientation = "PORTRAIT";
}
if(precision == 0.56) {
orientation = "LANDSCAPE";
}
if(resultHeight === resultWidth){
orientation = "SQUARE";
console.log(orientation);
}
$.ajax({
method: "PUT",
dataType: 'jsonp',
/*headers: {
"Authorization": "Basic " + btoa(USERNAME + ":" + PASSWORD)
},*/
url: urlLocation + imageid.value + "/orientation/" + orientation + "/image/" + saveImage,
/*data: {
imageid: imageid.value,
orientation: orientation,
image: saveImage,
},*/
success: function (data) {
$(".share-link").html("<div class='alert alert-success'><p>Success! " + imageid.value +" was posted.</p></div>");
console.log(data);
},
error: function (data) {
$(".share-link").html("<div class='alert alert-danger'><p>Couldn't send photo: <b>"+ imageid.value + "</b></p></div>");
}
});
});
resultHeight
andresultWidth
? - krillgarresultHeight === resultWidth
is impossible. Looking at the code in your question, that's the only way thatorientation
will be assigned to"SQUARE"
. - krillgar