<commit_before>'use strict';

/**
 * @file Helper for image file processing
 * For more information about Convert :
 * See http://www.imagemagick.org/script/convert.php
 */

var config = require('../../config/configuration.js');


/**
 * Extract the content of the specified file
 *
 * @param {string} path Path of the specified file
 * @param {function} cb Callback, first parameter, is the error if any, then the processed data
 */
module.exports = function (path, document, cb) {
  console.log(path, cb);
  var shellExec = require('child_process').exec;
  //convert models.png -auto-orient -thumbnail 350x250 thumb.png
  shellExec('convert ' + path + " -auto-orient -thumbnail " + config.thumb_size + " thumb.png", function(err, stdout, stderr) {
    if(err) {
      return cb(err);
    }
    if(stderr) {
      return cb(new Error(stderr));
    }

    cb(null, stdout);
  });
};<commit_msg>Generate thumb'<commit_after>'use strict';

/**
 * @file Helper for image file processing
 * For more information about Convert :
 * See http://www.imagemagick.org/script/convert.php
 */

var config = require('../../config/configuration.js');


/**
 * Extract the content of the specified file
 *
 * @param {string} path Path of the specified file
 * @param {function} cb Callback, first parameter, is the error if any, then the processed data
 */
module.exports = function (path, document, cb) {
  var shellExec = require('child_process').exec;
  // Initial command is:
  //convert original.png -auto-orient -thumbnail 350x250 thumb.png
  // Auto orient use EXIF information for orientation,
  // thumbnail strip metadatas and use a quick algorithm for generation in the given size
  // see http://www.imagemagick.org/Usage/thumbnails/
  // To retrieve data in stdout, we have to export onto fd:1 as png, so:
  //convert original.png -auto-orient -thumbnail 350x250 png:fd:1
  // Finally, to convert this raw data to base64 we use -i (ignore garbage) and -w 0 to disable linebreaks.

  shellExec('convert ' + path + " -auto-orient -thumbnail " + config.thumb_size + " png:fd:1 | base64 -i -w 0", function(err, stdout, stderr) {
    if(err) {
      return cb(err);
    }
    if(stderr) {
      return cb(new Error(stderr));
    }

    document.thumb = "data:image/png;base64," + stdout;

    cb(null, document);
  });
};
{'fraction_non_alphanumeric': 0.1331028522039758, 'fraction_numerical': 0.012532411408815903, 'mean_word_length': 3.3433395872420264, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 3, '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': '5420145', 'n_tokens_mistral': 732, 'n_tokens_neox': 699, 'n_words': 235}