客户端v/s服务器端图像压缩 [英] Client-Side v/s Server-Side image compression
问题描述
我正在做一些用户可以上传图片的事情(图片大小不受限制).现在,我有两个选择或者使用PHP(服务器端)压缩图像,或者使用JavaScript压缩客户端计算机上的图像,然后将其上传到服务器.我想问一下这两种方法中哪种方法更好?服务器上的压缩可能会导致服务器上的负担沉重,因此我想到了客户端压缩,但是,如果我上传较大尺寸的图像(假设为12MB左右),则由于脚本的原因,浏览器会冻结一段时间.
I am working on something where users can upload pictures(size of image is not limited). Now I have two options either compressing the image using PHP(Server side) or compressing the image on client's machine using JavaScript and then uploading it to the server. I wanted to ask which approach out of the two would be better to implement? Compression on server might lead to heavy load on the server so I thought of client side compression however if I upload an image of bigger size (lets assume 12MB or so) then browser freezes up for a while due to the script.
因此,没有任何代码只是一个理论问题.目前我正在使用 J-I-C 用于客户端压缩
There is as such no code just a theoretical question. Currently I am using J-I-C for client side compression
还有其他用于客户端图像压缩的好的库吗?哪种方法会更好?任何帮助将不胜感激.
Any other good library for client side image compression? and which approach would be better? Any help would be much appreciated.
推荐答案
正如@Xorifelse所说,问题可能太广泛了",但这是一些想法.
As @Xorifelse said, the question might be "too broad", but here are some ideas.
- 用户输入不能被信任;通过在客户端进行压缩,无论如何,您都必须在服务器端进行一些完整性检查
- 图像压缩(或优化)涉及复杂的操作,与其他语言相比,JavaScript中的选择更少
- 由于操作很复杂,因此您给客户带来了压力;如果您不控制他们的配置(硬件,浏览器和VERS),那么这种情况几乎只能在Intranet中出现,那么您可能会降低(或使某些用户的浏览体验失败)
- 由于所有这些原因,与在服务器上添加资源相比,客户端的bug较难跟踪和修复,并且可能使您花费更多的开发成本.
- user input must not be trusted; by doing compression on the client-side, you will have to do some sanity check on the server side anyway
- image compression (or optimization) involve complex operations, there is less choice in JavaScript than in other languages
- since the operations are complex, you are putting the stress on your clients; if you don't control their configuration (hardware, browser and vers), a situation you can have almost only in an intranet, you will probably degrade (or fail) the browsing experience of some of your users
- for all those reasons, client-side bugs are harder to track and fix and can quickly cost you more in development than adding resources to your servers
- 您从服务器上卸载了一些计算
- 您可以帮助带宽较小但功能强大的计算机和最新浏览器的人们上传大图像
- http://www.graphicsmagick.org/
- http://www.vips.ecs.soton.ac.uk/
- https://blarg.co.uk/blog/comparison-of-jpeg-lossless-compression-tools ( jpegoptim 与 jpegrescan vs mozjpeg )
- http://www.graphicsmagick.org/
- http://www.vips.ecs.soton.ac.uk/
- https://blarg.co.uk/blog/comparison-of-jpeg-lossless-compression-tools (jpegoptim vs jpegtran vs jpegrescan vs mozjpeg)
- 如果您需要备用服务器,则可以在服务器负载不高的一天中的某个时间批量异步优化图像.
- 如果您有很多输入,则将优化发送到另一台服务器(例如:Amazon,DigitalOcean,Linode等处的按需虚拟机,因此仅在需要时付款)会比较便宜.而不是升级您的主"服务器
这篇关于客户端v/s服务器端图像压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!