检测JPEG图像质量 [英] Detect JPEG image quality

查看:598
本文介绍了检测JPEG图像质量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我允许用户上传图片。但是,我想保持JPEG质量不超过90%。我打算做的是检测当前的质量:
- 如果少于90%什么都不做
- 如果超过90%,比使用Image Magick将图像重新压缩到90%

I allow users to upload images. However, I want to keep JPEG quality not more than 90%. What I plan to do is to detect the current quality: - If less than 90% do nothing - If more than 90%, than use Image Magick to recompress the image to 90%

是否可以这样做?我更喜欢PHP,但任何语言都会有帮助。

Is it possible to do that? I prefer PHP but any language will help.

推荐答案

paddy是正确的,这个设置并不总是存储在JPEG文件中。如果是,则可以使用Imagemagick中的标识来读取质量。例如:

paddy is correct that this setting is not always stored in the JPEG file. If it is, then you can use identify from Imagemagick to read the quality. For example:

$ identify -format '%Q' tornado_ok.jpg

93%


更新:根据这个问题的答案
https://superuser.com/questions/62730/how-to-找到jpg质量 I
发现显然识别命令仍然可以通过逆向工程量化确定质量
表即使所有
图像EXIF /其他元数据都丢失了。顺便说一句,
你现在的问题的标题是我链接到的那个
问题的可能重复。

Update: Based on the answer to this question https://superuser.com/questions/62730/how-to-find-the-jpg-quality I find out that apparently the identify command can still determine the quality by reverse engineering the quantization tables even if all the image EXIF / other meta data is lost. By the way, the title of your question as it stands now is a possible duplicate of that question I linked to.

但对我来说你的问题本身是有价值的,因为在你的
问题的文本中,你解释了你想要做什么,这比仅仅检测jpeg质量更多
。不过,如果你想要反映出你试图解决
更具体的问题而不仅仅是读取JPEG图像质量,那么你应该更新标题

But to me your question has merit on its own because in your question's text you explain what you are trying to do, which is more than simply detecting jpeg quality. Nevertheless, you should perhaps update the title if you want to reflect that you are trying to solve a more specific problem than just reading JPEG image quality.

除非您要归档原始图像,否则对于Web使用,即使90%也是过量的。过去75%曾经是默认值(只有在并排图像之间仔细检查才能看到降级),现在在高带宽的时候,85%是一个非常高质量的选择。 90%和85%之间的5%质量差异实际上是不可见的,但通常会节省超过30%的文件大小。 JPEG算法旨在首先消除人类感知在其第一个压缩阶段(超过80%左右)不可见的信息。

Unless you are archiving original images, for web use even 90% is excessive. 75% used to be the default in the old days (degradation was visible only under close inspection between side-by-side images), and now in the days of high bandwidth 85% is a very high quality option. The 5% quality difference between 90% and 85% is virtually invisible, but will save you over 30% in file size typically. The JPEG algorithm is designed to begin by eliminating information that is invisible to human perception at its first compression stages (above 80% or so).


更新/注意:我所讨论的压缩质量设置是来自libjpeg测试的
,libjpeg是一个使用非常广泛的JPEG库。 Photoshop的
压缩百分比和其他软件的质量设置都是
独立,并不一定意味着与libjpeg的设置
相同。

Update/note: The compression quality settings I am talking about are from tests with libjpeg, a very widely used JPEG library. Photoshop's compression percentages and other software's quality settings are all independent and do not necessarily mean the same thing as the settings of libjpeg.

paddy使用图像高度和图像宽度计算可接受文件大小的想法是合理的:

paddy's idea of using image height and image width to calculate an acceptable file size is reasonable:

你可以得到图像高度/像这样的宽度:

You can get the image height/width like this:

list($originalWidth, $originalHeight) = getimagesize($imageFile);

我自己在网上发布的高质量照片,如下所示: http://ksathletics.com/2013/wsumbb/nw.jpg
通常以以下比例保存每百万像素约200 KB。

My own high-quality photos posted online, like this one: http://ksathletics.com/2013/wsumbb/nw.jpg are typically saved at a ratio of about 200 KB per megapixel.

因此,例如,您可以将宽度乘以高度乘以1000000以计算图像中的百万像素。将文件大小除以1024以计算KB。然后将得到的KB除以百万像素。如果结果低于200或您决定的任何值,则无需重新压缩它。否则,您可以使用85%的质量或您决定的任何质量重新压缩它。

So, for example, you can multiply width times height and divide by 1000000 to calculate the megapixels in the image. Divide the file size by 1024 to calculate the KB. Then divide the resulting KB by the megapixels. If the result is under 200 or whatever value you decide upon, then you don't need to re-compress it. Otherwise, you can re-compress it with a quality of 85% or whatever quality you decide on.

这篇关于检测JPEG图像质量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆