Bahadır Gököz

get percentage of image loading - javascript

function getLoadingPercentage(imgUrl){
    Image.prototype.onChangeSize;
    Image.prototype.load = function(url){
        var _this = this;
        var req   = ((XMLHttpRequest) ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"));
        req.open('GET', url, true);
        req.responseType = 'arraybuffer';
        req.onload = function(e) {
          if(req.response) {
            var blob = new Blob([req.response]);
            _this.src = window.URL.createObjectURL(blob);
          }
        }
        req.onprogress = function(e) {
          if(_this.onChangeSize) {
            _this.onChangeSize(e.loaded, e.total);
          }
        }
        req.send();
    }
    var img = new Image();
    img.onChangeSize = function(loaded, total) {
        var loadingPercentage = parseInt((loaded / total) * 100);
        console.log(loaded + " - " + total + " byte - " + loadingPercentage);
    }
    img.onload = function() {
      //load completed actions here.
      alert("100% Completed");
    }
    img.load(imgUrl);
}

getLoadingPercentage("https://upload.wikimedia.org/wikipedia/commons/7/7a/Salzburg_from_Gaisberg_big_version.jpg");

run pure js example: https://jsfiddle.net/bhdrgkz/788ym94v/
run with jquery example: https://jsfiddle.net/bhdrgkz/788ym94v/3/

glob.hasMagic is not a function

MacOS’ta

Running "imagemin:dynamic" (imagemin) task
Fatal error: glob.hasMagic is not a function

yukarıdaki grunt imagemin problemi çözümü:

npm i --save-dev grunt-contrib-imagemin

kill node process

ps -ef | grep node

aktif processleri bulalım.

sudo kill -9 <PID>

ile öldürelim.