<commit_before>'use strict';

var _ = require('lodash'),
	Message = require('../modules/utils').message;

module.exports = function( image, output ){
	Message('log', 'Rendering:', output);

	var index = 0,
		glitch = image.glitch.data,
		bitmap = image.bitmap.data;

	_.each(glitch, function( pixel ){
		bitmap[index] = pixel.r;
		bitmap[index + 1] = pixel.g;
		bitmap[index + 2] = pixel.b;
		bitmap[index + 3] = pixel.a;
		index += 4;
	});
	image.write(output);

	Message('log', '');
};<commit_msg>Rendering to Base64 (returns Promise)<commit_after>'use strict';

var _ = require('lodash'),
	Promise = require('bluebird'),
	Message = require('../modules/utils').message;

module.exports = function( image, output ){
	Message('log', 'Rendering:', output);

	var index = 0,
		glitch = image.glitch.data,
		bitmap = image.bitmap.data;

	_.each(glitch, function( pixel ){
		bitmap[index] = pixel.r;
		bitmap[index + 1] = pixel.g;
		bitmap[index + 2] = pixel.b;
		bitmap[index + 3] = pixel.a;
		index += 4;
	});

	if(output !== 'base64'){
		image.write(output);
	} else {
		return new Promise(function( resolve, reject ){
			if( _.isUndefined(image) || _.isNull(image) ){
				reject();
			}

			image.getBuffer(image.bitmap.mime, function(err, buffer){
				resolve(buffer.toString('base64'));
			});
		});
	}

	Message('log', '');
};
{'fraction_non_alphanumeric': 0.19413092550790068, 'fraction_numerical': 0.012039127163280662, 'mean_word_length': 3.9442379182156135, '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': '5285957', 'n_tokens_mistral': 517, 'n_tokens_neox': 476, 'n_words': 98}