(function () { varCoverimage = Document.queryselector (' <div id= ' coverimage ' >file</div> '); //image CompressionCoverimage.onchange =function() {Lrz ( This. files[0], {width:640},function(results) {//The data you need is here, and can be sent as a string base64 to the server dump as a picture. varBase64 =results.base64; functionBase64urltoblob (base64) {varBytes=window.atob (Base64.split (', ') [1]);//remove the header from the URL and convert it to byte //handling exceptions, converting ASCII codes less than 0 to greater than 0 varAB =NewArrayBuffer (bytes.length); varIA =NewUint8array (AB); for(vari = 0; i < bytes.length; i++) {Ia[i]=bytes.charcodeat (i); } return NewBlob ([ab], {type: ' image/jpg '});//return Blob Object } varFormData =NewFormData ($ ("#toPic") [1]); varBlob =Base64urltoblob (base64); Console.log (BLOB); Formdata.append ("Coverimage", BLOB); $.ajax ({URL:"XXX", type:"POST", Data:formdata, DataType:"JSON", ContentType:false, ProcessData:false, Success:function(JSON) {console.log (JSON); }, }); SetTimeout (function() {Demo_report (' Pre-pressure pictures ', base64, Base64.length * 0.5); }, 100); }); };}) ();
(function () {
var coverimage = document.queryselector (' <div id= ' coverimage ' >file</div> ');
Image compression
Coverimage.onchange = function () {
Lrz (This.files[0], {width:640}, function (results) {
The data you need is here, and can be sent as a string base64 to the server dump as a picture.
var base64 = results.base64;
function Base64urltoblob (base64) {
var Bytes=window.atob (Base64.split (', ') [1]); Remove the header from the URL and convert it to byte
Handling exceptions, converting ASCII codes less than 0 to greater than 0
var ab = new ArrayBuffer (bytes.length);
var ia = new Uint8array (AB);
for (var i = 0; i < bytes.length; i++) {
Ia[i] = bytes.charcodeat (i);
}
return new Blob ([ab], {type: ' image/jpg '}); Return BLOB Object
}
var formData = new FormData ($ ("#toPic") [1]);
var blob = Base64urltoblob (base64);
Console.log (BLOB);
Formdata.append ("Coverimage", blob);
$.ajax ({
URL: "XXX",
Type: "POST",
Data:formdata,
DataType: "JSON",
Contenttype:false,
Processdata:false,
Success:function (JSON) {
Console.log (JSON);
},
});
SetTimeout (function () {
Demo_report (' Pre-pressure pictures ', base64, base64.length * 0.5);
}, 100);
});
};
})();
The image is base64 compressed, can be sent as a string base64 to the server to dump the image