<commit_before>var exec = require('child_process').exec;
var fs = require('fs');
var Mustache = require('mustache');
var async = require('async');
var os = require('os');

var packing = require('./packing/packing.js');
/**
 * Generate temporary trimmed image files
 * @param {string[]} files
 * @param {object} options
 * @param {boolean} options.trim is trimming enabled
 * @param callback
 */
exports.trimImages = function (files, options, callback) {
  if (!options.trim) return callback(null);

  var i = 0;
  async.eachSeries(files, function (file, next) {
    file.originalPath = file.path;
    i++;
    file.path = os.tmpDir() + 'image_' +i;

    //have to add 1px transparent border because imagemagick do trimming based on border pixel's color
    exec('convert -define png:exclude-chunks=date ' + file.originalPath + ' -bordercolor transparent -border 1 -trim ' + file.path, next);
  }, callback);
};

/**
 * Iterates through given files and gets its size
 * @param {string[]} files
 * @param {object} options
 * @param {boolean} options.trim is trimming enabled
 * @param {function} callback
 */
exports.getImagesSizes = function (files, options, callback) {
  var filePaths = files.map(function (file) {
    return '"' + file.path + '"';
  });
  exec('identify ' + filePaths.join(' '), function (err, stdout) {
    if (err) return callback(err);

    var sizes = stdout.split('\n');
    sizes = sizes.splice(0, sizes.length - 1);
    sizes.forEach(function (item, i) {
      var size = item.match(/ ([0-9]+)x([0-9]+) /);
      files[i].width = parseInt(size[1], 10);
      files[i].height = parseInt(size[2], 10);
      files[i].trimmed = false;

      if (options.trim) {
        var rect = item.match(/ ([0-9]+)x([0-9]+)\+([0-9]+)\+([0-9]+) /);
        files[i].trim = {};
        files[i].trim.x = parseInt(rect[3], 10) - 1;
        files[i].trim.y = parseInt(rect[4], 10) - 1;
        files[i].trim.width = parseInt(rect[1], 10) - 2;
        files[i].trim.height = parseInt(rect[2], 10) - 2;

        files[i].trimmed = (files[i].trim.width !== files[i].width || files[i].trim.height !== files[i].height);
      }<commit_msg>fixed parsing image size<commit_after>var exec = require('child_process').exec;
var fs = require('fs');
var Mustache = require('mustache');
var async = require('async');
var os = require('os');

var packing = require('./packing/packing.js');
/**
 * Generate temporary trimmed image files
 * @param {string[]} files
 * @param {object} options
 * @param {boolean} options.trim is trimming enabled
 * @param callback
 */
exports.trimImages = function (files, options, callback) {
  if (!options.trim) return callback(null);

  var i = 0;
  async.eachSeries(files, function (file, next) {
    file.originalPath = file.path;
    i++;
    file.path = os.tmpDir() + 'image_' +i;

    //have to add 1px transparent border because imagemagick do trimming based on border pixel's color
    exec('convert -define png:exclude-chunks=date ' + file.originalPath + ' -bordercolor transparent -border 1 -trim ' + file.path, next);
  }, callback);
};

/**
 * Iterates through given files and gets its size
 * @param {string[]} files
 * @param {object} options
 * @param {boolean} options.trim is trimming enabled
 * @param {function} callback
 */
exports.getImagesSizes = function (files, options, callback) {
  var filePaths = files.map(function (file) {
    return '"' + file.path + '"';
  });
  exec('identify ' + filePaths.join(' '), function (err, stdout) {
    if (err) return callback(err);

    var sizes = stdout.split('\n');
    sizes = sizes.splice(0, sizes.length - 1);
    sizes.forEach(function (item, i) {
      var size = item.match(/ ([0-9]+)x([0-9]+) /);
      files[i].width = parseInt(size[1], 10);
      files[i].height = parseInt(size[2], 10);
      files[i].trimmed = false;

      if (options.trim) {
        var rect = item.match(/ ([0-9]+)x([0-9]+)[\+\-]([0-9]+)[\+\-]([0-9]+) /);
        files[i].trim = {};
        files[i].trim.x = parseInt(rect[3], 10) - 1;
        files[i].trim.y = parseInt(rect[4], 10) - 1;
        files[i].trim.width = parseInt(rect[1], 10) - 2;
        files[i].trim.height = parseInt(rect[2], 10) - 2;

        files[i].trimmed = (files[i].trim.width !== files[i].width || files[i].trim.height !== files[i].height);
      }
{'fraction_non_alphanumeric': 0.1860032550569635, 'fraction_numerical': 0.01813531736805394, 'mean_word_length': 3.319277108433735, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '4776486', 'n_tokens_mistral': 1465, 'n_tokens_neox': 1420, 'n_words': 363}