Image Optimization (Google App Engine with Python)

强颜欢笑 提交于 2019-12-05 06:31:40

问题


I haven't found a similar question that I'm looking for Image Optimization.

I've tested how much Facebook can optimize the image uploaded:

980KB --> 77KB

846KB --> 62.1KB

From what I found out, Facebook is capable of optimizing the image up to 10 times while still pertaining some minimum image quality, as for the test above.

So, can anyone share what are the best ways that you have implemented to optimize image uploaded by user ?

When I searched in internet, I've seen some websites offer paid service for image optimization. However, we prefer not to subscribe for any paid service for image optimization at this stage.

I'm developing the project with Python language within Google App Engine environment. Any part where we can reuse from Python libraries or even Google App Engine libraries to achieve so ?


回答1:


Probably you should star this issue to get pngcrush like functionality added to the AppEngine images API.




回答2:


Basic optimization boils down to:

  1. Choosing the appropriate format for the image (usually jpeg for photographs; you can use jpeg across the board if you're not concerned about image quality but otherwise png for screenshots etc. may be wise)

  2. Reducing the image to the smallest resolution appropriate for your application

  3. Increasing the compression level to the highest level possible while maintaining your quality standards

You can also nitpick by stripping extraneous metadata, but that is usually unnecessary and not desirable.

If you want to do all of this in an automated fashion, you'll have to set a standard format and compression level across the board and accept that it won't be perfect in all cases, or else be able to determine what settings are appropriate for the image programmatically (which is quite difficult, unless you simply ask your users at upload time directly).

Normally I would use ImageMagick via the PythonMagick bindings for this task, but that may not be feasible on Google Apps Engine. In that case, maybe look at the Python Imaging Library.




回答3:


Another solution is to use a 3rd party api, in this case you can use tinyPNG. There compression algorithm is probably one of the best out there. Check there developer guide here ~>

https://tinypng.com/developers

The first 500 photos per month are free & it's like $0.009 per image (> 500 && < 9500) or $0.002 > 10000 images.




回答4:


You can't use PythonMagick unfortunately. But Python Imaging Library can be installed, and see Google Imaging Service on how to use it.

There is no magic bullet facebookesque optimization. You will have to try to develop your own that meets the standards you need. Most images these days are 5mp and up resizing them to 1280x720 or less is normal in web sites. The ability to crop extraneous image is also desirable before resizing.



来源:https://stackoverflow.com/questions/10970864/image-optimization-google-app-engine-with-python

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