下载调整后的图像,并设置新的宽度和高度
Download reiszed image with it's the new widh and height
基本上,我正在尝试调整图像的大小并下载它的新宽度和高度,但它只下载它的原始版本:
jQuery(document).ready(function() {
jQuery(function () {
jQuery(":file").change(function () {
if (this.files && this.files[0]) {
var reader = new FileReader();
reader.onload = imageIsLoaded;
reader.readAsDataURL(this.files[0]);
orginalWidth = $("#image").width();
orginalheight = $("#image").height();
// alert(orginalheight);
var images = jQuery('.thumb-wrapper img'); //caches the query when dom is ready
// var CELL_WIDTH = 150;
var ASPECT = 1.5;
jQuery( "#slider" ).slider({
step: 5,
min: 70,
max: 200,
value: 100,
slide: function(event, ui) {
var size = (orginalWidth * ui.value /10) + "px";
// alert(size);
images.stop(true).animate({width: size, height: size / ASPECT}, 250);
}
});
}
});
});
function imageIsLoaded(e) {
jQuery("#download").removeAttr("style");
jQuery("#file").css("display", "none");
jQuery('#image').attr('src', e.target.result);
jQuery('#download').attr('href', e.target.result);
};
});
HTML:
<div id="slider"></div>
<div class="file-list">
<div class="file-cell">
<div class="thumb-wrapper">
<input id="file" type='file' style=""/>
<img id="image" src="#" alt="your image" />
<a id="download" href="#" download="filename.jpg" style="display:none;">Download</a>
</div>
</div>
</div>
这里有一个Jsfiddle demo
有什么解决办法吗?感谢!
您现在正在做的是使浏览器在不改变原始图像的情况下调整视口中图像的大小。您需要做的是编写一个脚本来调整图像服务器端的大小。您可以使用jQuery将图像发布到服务器并获得调整后的图像。
相关文章:
- 为img设置高度和宽度
- jQuery在.show期间设置高度动画('幻灯片')
- textarea根据内容js或jquery设置高度
- 如何设置高度:0
- 页脚在滚动底部时没有设置高度动画
- iFrame - 在 iFrame 中更改内容时自动设置高度
- jQuery 断头台插件 - 在哪里设置高度和宽度
- 如何防止在 Safari 中使用 javascript 设置高度后在页面加载时运行过渡
- 如何使用 javascript 使用 ::before 选择器为元素设置高度
- 溢出:即使设置高度也自动不起作用
- 根据 jQuery 中多个实例上的另一个元素高度设置高度
- extJs(设置高度和宽度)(以百分比表示)
- 设置高度动画时元素跳跃
- 设置高度'单击按钮时元素的s
- jQuery:设置高度<部分>达到所有孩子的身高
- ExtJs,从不同版本的iframe创建窗口,正确设置高度
- Internet Explorer 7框架,设置高度为100%
- 如何设置高度或填充在选择框(下拉框)为safari和chrome
- JQuery获取和设置高度
- 需要一些jQuery滑动框脚本的帮助,以设置高度等于文本