简体   繁体   English

如何使用HTML5或Javascript找到上传图像的分辨率?

[英]How do I find the resolution of an uploaded image using HTML5 or Javascript?

My application uses the File API in HTML5 to have drag and drop capabilities. 我的应用程序使用HTML5中的File API来具有拖放功能。 I also needed to ensure that the files that are dropped obey a 72 pixels/inch resolution ratio. 我还需要确保丢弃的文件遵循72像素/英寸的分辨率。

How do I find the resolution of the image using HTML5 or Javascript? 如何使用HTML5或Javascript找到图像的分辨率?

DPI is a hardware measurement, more specifically used in print, and doesn't apply to image data when viewed on a screen. DPI是一种硬件度量,更专门用于打印,在屏幕上查看时不适用于图像数据。 A pixel is a pixel and the size of it depends on the resolution of the screen you are viewing it on, not a setting in the image file. 像素是像素,其大小取决于您在其上查看屏幕的分辨率,而不是图像文件中的设置。

If an image is 72 DPI and 72 px wide, it will show up as 72 px wide. 如果图像的宽度为72 DPI,宽度为72 px,则它将显示为72 px。 If an image is 144 DPI and 72 px wide, it will show up as the same size on the screen. 如果图像的分辨率为144 DPI,宽度为72 px,它将在屏幕上显示为相同大小。 However, in print the 144 DPI image will be half the width as th 72 DPI image. 但是,在打印时144 DPI图像的宽度是72 DPI图像宽度的一半。

Here's a (slightly outdated) JavaScript EXIF Reader . 这是一个(略过时的) JavaScript EXIF Reader

I would also recommend reading this answer here on SO. 我还建议您在此处阅读此答案

You can use blueimp Javascript-Load-Image library . 您可以使用blueimp Javascript-Load-Image库 You can use exif data parsing methods to parse image dpi and other informations from the image. 您可以使用exif数据解析方法来解析图像dpi和图像中的其他信息。 You can load the image locally from file tags or from the image urls as per requirement. 您可以根据需要从文件标签或图像URL本地加载图像。

Mostly jpeg images and raw image formats store dpi information in exif data. 通常,jpeg图像和原始图像格式将dpi信息存储在exif数据中。 Other formats like png don't have provisions for exif data and hence dpi of such images are difficult to extract without actually loading them in image editing tools like photoshop. 其他格式(例如png)没有exif数据的规定,因此,如果不将其实际加载到诸如photoshop之类的图像编辑工具中,则很难提取此类dpi的dpi。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM