IOS6已经发布,我一直在测试照片上传.
它效果很好,但是通过3G上的图像越大,它就像预期的那样缓慢.
感谢File API和Canvas,可以使用JavaScript调整图像大小.我希望如果我在尝试上传图像之前调整图像大小,它们会更快上传 - 这样可以提高用户体验.随着智能手机处理器以比网络速度快的速度增长,我相信这个解决方案是一个胜利者.
Nicolas为图像大小调整提供了出色的解决方案:
但是,我最难用jQuery的Ajax实现它.任何建议或帮助都表示赞赏,因为此代码可能对IOS6后的移动Web应用程序开发非常有用.
var fileType = file.type,
reader = new FileReader();
reader.onloadend = function () {
var image = new Image();
image.src = reader.result;
image.onload = function () {
//Detect image size
var maxWidth = 960,
maxHeight = 960,
imageWidth = image.width,
imageHeight = image.height;
if (imageWidth > imageHeight) {
if (imageWidth > maxWidth) {
imageHeight *= maxWidth / imageWidth;
imageWidth = maxWidth;
}
} else {
if (imageHeight > maxHeight) {
imageWidth *= …Run Code Online (Sandbox Code Playgroud)