扫码关注官方订阅号
当用户通过浏览器上传图片时,不管用户用了多大的图片,都使其能够上传,现在想用JS先在浏览器上对图片进行压缩处理,然后上传,而不是将整个图片上传到后台服务器然后在压缩后存储。请问这种方案是否可行?新浪微博在上传图片的时候是怎样一种解决方案?请各路大牛不吝赐教!谢谢。
欢迎选择我的课程,让我们一起见证您的进步~~
如果要所有运算都在客户端通过js完成,目前只有html5的canvas和file api才能满足你的需要。但是对国内用户来说,支持html5的浏览器普及率还不够高。
新浪微博的图片上传使用的是图片上传后然后,再在服务器端压缩的方法,实际上这种方式的消耗也很少。目前普遍上使用的都是这种方式,因为只需要在上传的时候压缩一次。
<script language="JavaScript" type="text/javascript"> function DrawImage(ImgD,FitWidth,FitHeight) { var image=new Image(); image.src=ImgD.src; if(image.width>0 && image.height>0) { if(image.width>FitWidth) { ImgD.width=FitWidth; ImgD.height=(image.height*FitWidth)/image.width; if(ImgD.height>FitHeight) { ImgD.height=FitHeight; ImgD.width=(image.width*FitHeight)/image.height; } } else if(image.height>FitHeight) { ImgD.height=FitHeight; ImgD.width=(image.width*FitHeight)/image.height; if(image.width>FitWidth) { ImgD.width=FitWidth; ImgD.height=(image.height*FitWidth)/image.width; } } else { ImgD.width=image.width; ImgD.height=image.height; } } } </script>
最近做一个页面时用到的,不知道符不符合你的需求!
也可以考虑用flash去实现压缩上传的功能
python的话,直接用PIL在服务器端处理就可以了,没必要做在客户端用js做
客户端的js改变图片的宽度和高度 是很难做到效果漂亮的,大部分情况都是服务器端语言压缩的
请问家有萌虎,关于exif 那里如何实现的
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2026 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
如果要所有运算都在客户端通过js完成,目前只有html5的canvas和file api才能满足你的需要。但是对国内用户来说,支持html5的浏览器普及率还不够高。
新浪微博的图片上传使用的是图片上传后然后,再在服务器端压缩的方法,实际上这种方式的消耗也很少。目前普遍上使用的都是这种方式,因为只需要在上传的时候压缩一次。
<script language="JavaScript" type="text/javascript"> function DrawImage(ImgD,FitWidth,FitHeight) { var image=new Image(); image.src=ImgD.src; if(image.width>0 && image.height>0) { if(image.width>FitWidth) { ImgD.width=FitWidth; ImgD.height=(image.height*FitWidth)/image.width; if(ImgD.height>FitHeight) { ImgD.height=FitHeight; ImgD.width=(image.width*FitHeight)/image.height; } } else if(image.height>FitHeight) { ImgD.height=FitHeight; ImgD.width=(image.width*FitHeight)/image.height; if(image.width>FitWidth) { ImgD.width=FitWidth; ImgD.height=(image.height*FitWidth)/image.width; } } else { ImgD.width=image.width; ImgD.height=image.height; } } } </script>最近做一个页面时用到的,不知道符不符合你的需求!
也可以考虑用flash去实现压缩上传的功能
python的话,直接用PIL在服务器端处理就可以了,没必要做在客户端用js做
客户端的js改变图片的宽度和高度 是很难做到效果漂亮的,大部分情况都是服务器端语言压缩的
请问家有萌虎,关于exif 那里如何实现的