是否有可能通過jquery/js調整或降低分辨率以減小文件大小?在我的HTML,我有窗體上傳多個圖像像這樣:是否有可能通過jquery/js調整或降低分辨率以減小文件大小?
<div class="form-group col-sm-12">
<label for="file">Upload Foto</label>
<input name="file[]" id="file" class="btn btn-primary" type="file" multiple >
</div>
<button class="btn btn-primary" type="submit" id="upload">Upload</button>
我想創建圖像調整大小berfore使用ajax上傳。這裏是jQuery代碼。
$(document).on('submit', '#upload', function() {
var inputFile = $('input#file');
var filesToUpload = inputFile[0].files;
if (filesToUpload.length > 0) {
// provide the form data that would be sent to sever through ajax
var formData = new FormData();
for (var i = 0; i < filesToUpload.length; i++) {
// Do something to resize image or reduce resolution for minimize delay upload
var file = filesToUpload[i];
formData.append("file[]", file, file.name);
}
$.ajax({
url: "<?php echo base_url('surveyor/c_surveyor/add_file_image/'); ?>/" + NO_TANK + EIR_REF,
type: 'post',
data: formData,
processData: false,
contentType: false,
success: function() {
$(":file").val('');
$(":text").val('');
$("#tableClean").find("tr:gt(0)").remove();
$("#tableReport").find("tr:gt(0)").remove();
$('#pilih_isotank').after('<div class="callout callout-success lead" id="div_error"><p id="pesan_error">Semua Data Berhasil Terupload</p></div>');
$('#div_error').fadeIn("fast");
$('#pesan_error').html(obj.Message);
$('#div_error').fadeOut(7000);
}
});
它可能可以通過畫布和很多工作來實現,但這通常是通過服務器完成的,因爲它非常容易。 – adeneo