已知尺寸的JPEG图像的最大文件大小
【腾讯云】亏本大甩卖,服务器4核16G 1年370元(带宽12M,系统盘120GB SSD盘,月流量2000GB)!!!!!!
云产品 配置 价格
服务器 1核2G,带宽5M,系统盘50GB SSD盘,月流量500GB 38元/年
MySQL 1核1G 19元/年
服务器 16核32G,带宽18M,系统盘250GB SSD盘,月流量5000GB 1197元/年
点我进入腾讯云,查看更多详情

I'm going to let users upload images of 300x300 compressed with JPEG. Is there a way to determine what the maximum file size of such an image would be?

I can imagine this can be tried by compressing random noise at 100 quality, but is there a theoretical maximum?

Say that the image is totally uncompressable random noise, could it be 3 bytes per pixel (24-bits colour) and a margin for the metadata? Or could such an image turn out larger than the original when compressed?

#0

From wikipedia:

For highest quality images (Q=100), about 8.25 bits per color pixel is required http://en.wikipedia.org/wiki/JPEG#Sample_photographs

So, for Q=100 on an 300x300 image, that would result in (300 * 300) px * 8.25 bits/px = 742,500 bits = ~ 93 kB

There are also lossless JPEG coding modes, which are practically not used (last sentence, second paragraph). But they would have the RGB typical 24 bits/pixel.

#1

There is no limit on jpeg metadata size, which means there's no limit to the size of a jpeg file. See this answer I've linked for an explanation of why and also for an example of a realistic situation where the metadata might get large: What is the maximum size of JPEG metadata?

So if assuming a maximum practical/realistic size suits your purpose, then you should factor that example into your calculations. In many contexts it would be fine to just reject things outside of that maximum as outside the domain of your program's intended usage.

But if you absolutely must rely on theoretical, then unfortunately it's a big bold

Note: I do not have a huge amount of personal experience with the jpeg specification, so I am going off of what people have said about repeated fields being allowed, as well as multiple comment fields. Please correct me if you find evidence to the contrary.

推荐文章

是否有工具可以编译只包含特定类型的“选择性”程序集?

是否有工具可以编译只包含特定类型的“选择性”程序集?

推荐文章

任何开源浏览器GUI自动化工具都支持在页面上的任何位置单击特定图标?

任何开源浏览器GUI自动化工具都支持在页面上的任何位置单击特定图标?

推荐文章

jQuery嵌套范围文本值

jQuery嵌套范围文本值

推荐文章

更改uidatepicker月份后,Cluetip不工作

更改uidatepicker月份后,Cluetip不工作

推荐文章

什么是Commons Lang?我如何使用它?(爪哇语)

什么是Commons Lang?我如何使用它?(爪哇语)

推荐文章

Rails模型关联表单问题

Rails模型关联表单问题

推荐文章

资源,放在哪里,以及如何在C中引用它们#

资源,放在哪里,以及如何在C中引用它们#

推荐文章

简单程序中的类序列化,我应该担心吗?

简单程序中的类序列化,我应该担心吗?

推荐文章

ASP.Net“记住我”功能

ASP.Net“记住我”功能

推荐文章

使用jQuery或javascript关注“多个”HTML输入字段

使用jQuery或javascript关注“多个”HTML输入字段

推荐文章

如何将手写文本分为不同的部分和单词?

如何将手写文本分为不同的部分和单词?

推荐文章

MATLAB scatter3,plot3速度离散

MATLAB scatter3,plot3速度离散

推荐文章

C#业务逻辑、业务对象、数据访问、项目

C#业务逻辑、业务对象、数据访问、项目

推荐文章

Netbeans Intellisense PHP迭代器接口

Netbeans Intellisense PHP迭代器接口

推荐文章

从另一个类访问变量-Objective-C

从另一个类访问变量-Objective-C

推荐文章

为什么C++中的布尔和指针的奇怪兼容性?

为什么C++中的布尔和指针的奇怪兼容性?