Lrz Compress pictures, upload seven cows

Source: Internet
Author: User
Tags documentation

Reference Documentation:

1.http://blog.csdn.net/zhongbaolin/article/details/49817611

2.https://github.com/think2011/localresizeimg

3.http://yunzhu.iteye.com/blog/2177923

4.http://blog.csdn.net/inuyasha1121/article/details/51915742

5.https://segmentfault.com/q/1010000005012250?_ea=753141


Demo Download Address: http://download.csdn.net/detail/u010947098/9725884


Compress the picture via Lrz and upload it to the seven cow server.

Lrz compression pictures online case quite a lot of, I am also the main card in the upload Seven cow server, has been using the seven-Qiniu JS SDK to upload pictures, but seven cattle provided by the JSSDK is based on the plupload of the expansion, with the compression function, only support JPG compression, does not support PNG And then decided to use the LRZ, but using seven cattle jssdk has been unable to upload to the seven cow server, finally through Android upload seven cattle server, grab packets to view the transmitted packets, and then use AJAX asynchronous request, send Formdata data, successfully uploaded Through the LRZ also completed the image compression function, the heart Meimei.

The following posted the code I wrote, the code is in the LRZ project based on the change for everyone's reference:

Here, thank the author of the reference documentation.

Window.onerror = function (ErrMsg, Scripturi, linenumber, ColumnNumber, errorobj) {settimeout (function () {V Ar rst = {"error message:": ErrMsg, "Error file:": Scripturi, "error line number:": linenumber, "error column number

        : ": ColumnNumber, Error Details:": errorobj};
        Alert (' Error, next display error message ');
    Alert (json.stringify (RST, NULL, 10));
});

}; [].foreach.call (Document.queryselectorall (' [data-src] '), function (EL) {(function (EL) {El.addeventlistener (

            ' Click ', Function () {el.src = ' img/loading.gif ';


                    Lrz (EL.DATASET.SRC). Then (function (rst) {el.src = rst.base64;
                return rst;
        });

        });
    FireEvent (el, ' click ');
}) (EL);

});


    Document.queryselector (' input '). AddEventListener (' Change ', function () {var "= this; Lrz (That.files[0], {width:800}). Then (function (RST) {var FormdATA = new FormData (); Formdata.append ("token", "qhdmc1g_uymrggxsjnrjnlxc9i-rsgqbjokszjfz:mzfli37nimtajikxwfuxksa4jpa=:
            eyjzy29wzsi6inlsenl5esisimrlywrsaw5lijoxndgzmtaxmzuzfq== ");
            Formdata.append ("file", Rst.file);
                $.ajax ({type: POST), url: "http://upload.qiniu.com/", Data:formdata,  Async:false, Cache:false, Contenttype:false, ProcessData:
                False, Beforesend:function (XMLHttpRequest) {//showloader (); }, Success:function (data) {if ("1" = Data.error) {alert (
                        Data.message);
                    return false;

                        else {alert (data.thumbnail);
                    return false; }, Complete:function (XMLHttpRequest, TextstatUS) {Hideloader ();
                    }, Error:function (XMLHttpRequest, Textstatus, Errorthrown) {//upload failed//hideloader ();
                Alert (' Operation error ');
            }
            });
        return rst;
});

});
Document.queryselector (' #version '). InnerHTML = Lrz.version; Document.queryselector ('.

UA '). InnerHTML = ' ua: ' + navigator.useragent;

function ToFixed2 (num) {return parsefloat (+num.tofixed (2));} /** * Replacement String! {} * @param obj * @returns {String} * @example * ' I am!
 {str} '. Render ({str: ' Test '});

    */String.prototype.render = function (obj) {var str = this, reg;
        Object.keys (obj). ForEach (function (v) {reg = new RegExp (' \\!\\{' + V + ' \} ', ' G ');
    str = str.replace (Reg, obj[v]);

    });
return str;

}; /** * Trigger Event-Just for Compatibility demo demo * @param element * @param event * @returns {Boolean}/function FireEvent (element, event

    ) {var evt; if (document.createeventobjECT) {//IE browser supports fireevent method evt = Document.createeventobject (); Return element.fireevent (' on ' + Event, evt)} else {//other standard browsers use dispatchevent method evt = document.cr
        Eateevent (' htmlevents ');
        Initevent accepts 3 parameters://Event type, bubbling, blocking browser default behavior Evt.initevent (event, True, true);
    Return!element.dispatchevent (EVT);        }/** * *┏┓┏┓*┏┛┻━━━┛┻┓*┃┃*┃━┃*┃┳┛┗┳┃*┃┃*┃┻┃*┃     ┃*┗━┓┏━┛code are far away from bugs with the animal protecting *┃┃ God bless, code no bugs *┃┃*
 ┃┗━━━┓*┃┣┓*┃┏┛*┗┓┓┏━┳┓┏┛*┃┫┫┃┫┫*┗┻┛┗┻┛* *














Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.