减少非常大的图像的文件大小,而不更改图像大小 [英] Reducing the file size of a very large images, without changing the image dimensions

查看:149
本文介绍了减少非常大的图像的文件大小,而不更改图像大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑处理上传可能非常大的PNG文件的应用程序。

Consider an application handling uploading of potentially very large PNG files.

所有上传的文件必须存储到磁盘以供日后检索。但是,PNG文件的大小可以高达30 MB,但磁盘存储空间限制最大为每个文件大小1 MB。

All uploaded files must be stored to disk for later retrieval. However, the PNG files can be up to 30 MB in size, but disk storage limitations gives a maximum per file size of 1 MB.

问题是采取输入PNG文件大小最大为30 MB,并产生文件大小小于1 MB的输出PNG。

The problem is to take an input PNG of file size up to 30 MB and produce an output PNG of file size below 1 MB.

这个操作显然是有损的 - 图像质量,颜色,等等都不是问题。然而,不能改变的一件事是图像尺寸。因此,尺寸为800x600的输入文件必须生成尺寸为800x600的输出文件。

This operation will obviously be lossy - and reduction in image quality, colors, etc is not a problem. However, one thing that must not be changed is the image dimension. Hence, an input file of dimension 800x600 must produce an output file of dimension 800x600.

上述要求是严格的,不能更改。

The above requirements outlined above are strict and cannot be changed.

使用ImageMagick(或其他一些开源工具)如何将大小为30 MB的输入PNG文件的文件大小减小到每个文件最大1 MB,不改变图片尺寸?

推荐答案

PNG不是有损图片格式,因此您可能需要将图像转换为另一种格式 - 最有可能是JPEG。 JPEG有一个可设置的质量因素 - 你可以简单地保持降低质量因子,直到你有一个足够小的图像。所有这一切都可以在不改变图像分辨率的情况下完成。

PNG is not a lossy image format, so you would likely need to convert the image into another format-- most likely JPEG. JPEG has a settable "quality" factor-- you could simply keep reducing the quality factor until you got an image that was small enough. All of this can be done without changing the image resolution.

显然,根据图像,视觉质量的损失可能是巨大的。 JPEG最适合真实生活的图像,如来自相机的图片。它不适用于徽标,屏幕截图或其他具有从明到暗的锐利过渡的图像。 (PNG,另一方面,具有相反的行为 - 它是最好的徽标等)

Obviously, depending on the image, the loss of visual quality may be substantial. JPEG does best for "true life" images, such as pictures from cameras. It does not do as well for logos, screen shots, or other images with "sharp" transitions from light to dark. (PNG, on the other hand, has the opposite behavior-- it's best for logos, etc.)

但是,在800x600,它很可能会很容易得到一个JPEG下降到1MB。 (我会很惊讶地看到一个30MB的文件,在这些小的维度。)事实上,即使未压缩,图像只有大约1.4MB:

However, at 800x600, it likely will be very easy to get a JPEG down under 1MB. (I would be very surprised to see a 30MB file at those smallish dimensions.) In fact, even uncompressed, the image would only be around 1.4MB:

800 pixels * 600 pixels * 3 Bytes / color = 1,440,000 Bytes = 1.4MB

因此,您只需要1.4:1的压缩比即可将图像缩小到1MB。根据图像的类型,PNG压缩可以非常好地提供该级别的压缩。如果不是,JPEG几乎肯定可以 - JPEG压缩率在10:1的数量级并不罕见。再次,输出的质量/大小将取决于图像的类型。

Therefore, you only need a 1.4:1 compression ratio to get the image down to 1MB. Depending on the type of image, the PNG compression may very well provide that level of compression. If not, JPEG almost certainly could-- JPEG compression ratios on the order of 10:1 are not uncommon. Again, the quality / size of the output will depend on the type of image.

最后,虽然我没有使用ImageMagick一段时间,我几乎肯定有使用特定品质因子重新压缩图像的选项。阅读文档,并开始尝试!

Finally, while I have not used ImageMagick in a little while, I'm almost certain there are options to re-compress an image using a specific quality factor. Read through the docs, and start experimenting!

编辑:看起来,它应该,实际上,应该很容易与ImageMagick。从文档

Looks like it should, indeed, be pretty easy with ImageMagick. From the docs:

$magick> convert input.png -quality 75 output.jpg

只要继续使用质量值,合适的输出。

Just keep playing with the quality value until you get a suitable output.

这篇关于减少非常大的图像的文件大小,而不更改图像大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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