上传前调整图像大小,但同步上传(不是ajax)。可能吗? [英] Resize image before upload, but upload synchronously (not ajax). Is it possible?

查看:144
本文介绍了上传前调整图像大小,但同步上传(不是ajax)。可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一些字段的表单,包括用于上传图像的输入类型='文件'。

我正在搜索调整此字段选择的图像大小的方法,但不是立即上传。

I have a form with some fields, including a input type='file', used to upload images.
I'm searching for a way to resize de image selected by this field, but not upload immediatly.

我已经阅读了一些教授以下过程的教程:

1 - 使用文件中的'onchange'事件捕获图像field;

2 - 创建一个具有所需图像大小的canvas元素;

3 - 在canvas元素中绘制图像并读取其内容;

4 - 使用FormData异步发送图像数据(ajax)。

I've read some tutorials that teaches the following proccess:
1 - catch the image using 'onchange' event on the file field;
2 - create a canvas element with the desired image size;
3 - draw the image in the canvas element and read its contents;
4 - send the image data asynchronously (ajax) using FormData.

我想在第3步之前做同样的事情,然后将调整后的图像与其他图像一起发送当用户点击表单的提交按钮时的字段。

I'd like to do the same thing until step 3, and then send the resized image together with the other fields when the user clicks the form's submit button.

有没有人有任何想法?

谢谢!

Does anybody have any idea?
Thanks!

Ps:一些几乎完成我想做的帖子:

http://coding.pressbi n.com/84/File-API-Resize-photo-before-upload/

调整HTML5画布中的图像大小

Ps: Some posts that ALMOST do what I desire:
http://coding.pressbin.com/84/File-API-Resize-photo-before-upload/
Resizing an image in an HTML5 canvas

推荐答案

如果你想要的话要调整图像大小以节省空间,请尝试:
http://www.researchandtechnology.net/bcif/

If your wanting to resize the image to save space try: http://www.researchandtechnology.net/bcif/

这是一种JavaScript图像压缩算法。

This is a JavaScript image compression algorithm.

这也可能有所帮助: Javascript无损图像压缩

并包含它与其他表单项base 64编码图像
如何使用javascript将图片转换为base64字符串

And to include it with other form items base 64 encode the image How to convert image into base64 string using javascript

并将其作为字符串发送

如果您的不试图这样做你能提供更多信息吗?

If your not trying to do this could you please give more information?

这篇关于上传前调整图像大小,但同步上传(不是ajax)。可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆