<commit_before>'use strict';

angular.module('lurinfacts').factory('ImageResizeService', function ($q) {

    var resizeImage = function (src, size) {
      // perform some asynchronous operation, resolve or reject the promise when appropriate.
      return $q(function (resolve, reject) {
        var img = new Image();
        img.onload = function () {
          var resized = resizeLoadedImage(img, size);
          resolve(resized);
        };
        img.onerror = function (e) {
          reject(e);
        };
        img.src = src;
      });
    };

    var resizeLoadedImage = function (image, size) {
      var mainCanvas = document.createElement('canvas');
      mainCanvas.width = 1024;
      mainCanvas.height = 768;
      var ctx = mainCanvas.getContext('2d');
      ctx.drawImage(image, 0, 0, mainCanvas.width, mainCanvas.height);
      //size = parseInt($('#size').get(0).value, 10);
      while (mainCanvas.width > size) {
        mainCanvas = halfSize(mainCanvas);
      }
      return mainCanvas.toDataURL('image/jpeg');<commit_msg>fix imageresizeservice for pictures in portrait mode<commit_after>'use strict';

angular.module('lurinfacts').factory('ImageResizeService', function ($q) {

    var resizeImage = function (src, size) {
      // perform some asynchronous operation, resolve or reject the promise when appropriate.
      return $q(function (resolve, reject) {
        var img = new Image();
        img.onload = function () {
          var resized = resizeLoadedImage(img, size);
          resolve(resized);
        };
        img.onerror = function (e) {
          reject(e);
        };
        img.src = src;
      });
    };

    var resizeLoadedImage = function (image, size) {
      var mainCanvas = document.createElement('canvas');
      //portrait or landscape image?
      mainCanvas.width = image.width < image.height ?  768 : 1024;
      mainCanvas.height = image.width > image.height ?  768 : 1024;
      var ctx = mainCanvas.getContext('2d');
      ctx.drawImage(image, 0, 0, mainCanvas.width, mainCanvas.height);
      //size = parseInt($('#size').get(0).value, 10);
      while (mainCanvas.width > size) {
        mainCanvas = halfSize(mainCanvas);
      }
      return mainCanvas.toDataURL('image/jpeg');
{'fraction_non_alphanumeric': 0.13093652907234798, 'fraction_numerical': 0.014647137150466045, 'mean_word_length': 2.6064, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 6, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1072266', 'n_tokens_mistral': 665, 'n_tokens_neox': 626, 'n_words': 159}