Compressing an image to make it less than 4KB

£可爱£侵袭症+ 提交于 2019-12-12 13:08:08

问题


I have an image of a person and I want to compress it to make it less than 4KB. I need to compress it and still have the face of the person recognizable even if the image will shrink.


回答1:


Here is Theresa May at 142kB:

and resized to 72x72 and converted to greyscale and reduced to 2kB with ImageMagick at the command line:

convert original.jpg -resize 72x72 -colorspace gray -define jpeg:extent=2kb result.jpg

I can still recognise her.


Here is some other guy reduced to 1kB and I can still recognise him too:

ImageMagick is installed on most Linux distros and is available for macOS and Windows. Bindings are available for Python, PHP, Ruby, Javascript, Perl etc.


If you had further knowledge about your images, or your recognition algorithm, you may be able to do better. For example, if you knew that the centre of the image was more important than the edges, you could slightly blur, or reduce contrast in relatively unimportant areas and use the available space for more details in the important areas.




回答2:


Mark Setchell has the right idea. But I might suggest one potential minor improvement. Remove any meta data including profiles, EXIF data etc. You can do that by either adding -strip

convert input.jpg -strip -resize 72x72 -colorspace gray -define jpeg:extent=2kb result.jpg


or by using -thumbnail rather than -resize. The former automatically does the strip.

convert input.jpg -thumbnail 72x72 -colorspace gray -define jpeg:extent=2kb result.jpg


来源:https://stackoverflow.com/questions/51353422/compressing-an-image-to-make-it-less-than-4kb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!