我使用jquery在上傳時調整圖像大小,這很好。但我的問題是我想發送調整大小的圖像,並且我想在輸入文件中設置新圖像的數據,以便在提交時將其發送到服務器。但我不能實現這一目標。每次它發送大文件。這裏是我的代碼:調整圖像大小並將其設置爲輸入文件
<div>
<input name="photo" type="file"/>
<p><span></span></p>
<i></i>
</div>
<script>
$().ready(function() {
$("input[name*='photo']").change(function(e) {
var file = e.target.files[0];
// RESET
$('#area p span').css('width', 0 + "%").html('');
$('#area img, #area canvas').remove();
// CANVAS RESIZING
$.canvasResize(file, {
width: 300,
height: 0,
crop: false,
quality: 80,
//rotate: 90,
callback: function(data, width, height) {
// SHOW AS AN IMAGE
$('<img>').load(function() {
$(this).css({
'margin': '10px auto',
'width': width,
'height': height
}).appendTo('#area div');
}).attr('src', data);
// here i am trying to assign the resized data to my image from my input file
$(this).files[0] = data;
}
});
});
});
</script>
<script src="jqLibrary/jquery.exif.js"></script>
<script src="jqLibrary/jquery.canvasResize.js"></script>
<script src="jqLibrary/canvasResize.js"></script>
</div>
相關https://stackoverflow.com/q/47515232/584192 –