【发布时间】:2022-11-13 01:46:09
【问题描述】:
当用户上传时,我在检查非 A4 尺寸的图像时遇到问题。
当用户上传时,我在检查不是 A4 尺寸的图像时遇到问题。例如,如果宽度为 1200,高度为 1301,我的代码将其视为 A4,但如果宽度和高度相同,则不会。我的问题是,如何检查图像是否不是 A4?
我只是关注这个资源:https://codepen.io/Niklan/pen/vXzBpE 和 https://codepen.io/html5andblog/pen/WQYOyN
代码: `
var ratio = 1.41451612903;
img.onload = function() {
//landscape
if (img.naturalWidth > img.naturalHeight) {
// check A4 size in pixel with ratio
if (Math.floor(this.height * ratio) && Math.floor(this.width * ratio /
2)) {
errorImage.innerHTML = ``;
} else {
errorImage.innerHTML = 'Please upload A4 image.';
}
//potrait
} else if (img.naturalWidth < img
.naturalHeight) {
if (Math.floor(this.width * ratio / 2) && Math.floor(
this.width * ratio)) {
errorImage.innerHTML = ``;
} else {
errorImage.innerHTML = 'Please upload A4 image.';
}
} else {
errorImage.innerHTML =
'Picture must be in A4 portrait or landscape.';
}
_URL.revokeObjectURL(objectUrl);
};
`
【问题讨论】:
标签: javascript jquery reactjs vue.js