【问题标题】:Check if the image not A4检查图像是否不是 A4
【发布时间】:2022-11-13 01:46:09
【问题描述】:

当用户上传时,我在检查非 A4 尺寸的图像时遇到问题。

当用户上传时,我在检查不是 A4 尺寸的图像时遇到问题。例如,如果宽度为 1200,高度为 1301,我的代码将其视为 A4,但如果宽度和高度相同,则不会。我的问题是,如何检查图像是否不是 A4?

我只是关注这个资源:https://codepen.io/Niklan/pen/vXzBpEhttps://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


    【解决方案1】:

    不是答案,而是警告。

    如果您绝对需要检查 A4 作为表面格式,例如21x29,7cm,必须检查图像的DPI。

    例子 :72 DPI A4 像素为 595 x 842 像素。 300 DPI A4 像素为 2480 x 3508 像素。

    知道这一点的最简单方法是检查 EXIF 数据(如果存在)。

    笔记:其实DPI主要是为了restitution(print,screen),它是一种简写,或许更好的称呼它为RESOLUTION

    【讨论】:

      猜你喜欢
      • 2018-04-28
      • 2016-10-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-20
      • 2012-12-04
      相关资源
      最近更新 更多