简体   繁体   English

Django在客户端上传之前调整图像大小

[英]Django resize image before upload on client side

I used PIL to resize image before saving but forgot that the clients uploading the images (sometimes really big images), have to wait a long time before the image is transferred to the server.我在保存之前使用 PIL 调整图像大小,但忘记了客户端上传图像(有时非常大的图像),必须等待很长时间才能将图像传输到服务器。

I figured the best way to do this is via client-side, probably with html5 and JavaScript.我认为最好的方法是通过客户端,可能使用 html5 和 JavaScript。 I found this: http://hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/ but it shows no working example and does not show it in Django tempting language context.我发现了这个: http : //hacks.mozilla.org/2011/01/how-to-develop-a-html5-image-uploader/但它没有显示工作示例,也没有在 Django 诱人的语言上下文中显示它。 I also found this:我也发现了这个:

Image resize before upload and it says it works in toolkit and Mozilla browsers. 上传前图像调整大小,它说它适用于工具包和 Mozilla 浏览器。

Is there a JavaScript library out there that does this and works with IE as well?是否有一个 JavaScript 库可以做到这一点并且也适用于 IE? Is there a Django templating language example out there?那里有 Django 模板语言示例吗?

Are you uploading images by submitting a form?您是通过提交表单上传图片吗? This: http://blueimp.github.io/jQuery-File-Upload/ will display a progress bar in the browser, and can resize images in the client using Javascript.这个: http : //blueimp.github.io/jQuery-File-Upload/将在浏览器中显示一个进度条,并且可以使用 Javascript 在客户端调整图像大小。 It is also cross browser compatible.它也是跨浏览器兼容的。

However, it does require implementing ajax in django, and the styling uses jquery-ui which may not fit into the rest of your design.但是,它确实需要在 django 中实现 ajax,并且样式使用 jquery-ui,这可能不适合您设计的其余部分。

I can post some example code if that would help, there is an example django project here: https://github.com/sigurdga/django-jquery-file-upload , or an example on SO: How to add image into a post in django .如果有帮助,我可以发布一些示例代码,这里有一个示例 django 项目: https : //github.com/sigurdga/django-jquery-file-upload ,或关于 SO 的示例: 如何将图像添加到帖子中在 Django 中

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM