<commit_before>'use strict';

var gm = require('gm').subClass({
    imageMagick: true
});

var getCrName = (imgFilename) => {
    return imgFilename.toLowerCase().replace('.jpg', '-cr.jpg');
};

var overlayCopyrights = (imgFilename, image, isPortrait) => {
    var imageCrName = getCrName(imgFilename);
    var imageCr;
    // var watermarkFile = 'img/Copyright640640-7percent.png';
    var sewnInUsa = 'img/sewnInUsa40-transparent.png';
    var hingmadeEtsyCom = 'img/hingmade-etsy-com.png';
    var hingmadeEtsyComGeo = isPortrait ? '-90+30' : '-90+10';
    image
        // .composite('img/Copyright.gif')
        .composite(sewnInUsa)
        .geometry('+10+10')
        .gravity('SouthEast')
        .write(imageCrName, function (err) {
            if (err) {
                console.log(err);
            } else {
                console.log(imgFilename, '===> done adding copyright text');
                imageCr = gm(imageCrName);
                imageCr
                    // .composite(watermarkFile)
                    .composite(hingmadeEtsyCom)
                    .geometry(hingmadeEtsyComGeo)
                    .gravity('North')
                    .write(imageCrName, function (err) {
                        if (err) {
                            console.log(err);
                        } else {
                            console.log(imgFilename, '===> done adding copyright watermark');
                        }
                    }); 
            }
        });
};

var addCopyright = (imgFilename) => {
    let image = gm(imgFilename);
    // image.orientation((err, value) => {
        // TODO: handle err
        // let isPortrait = (value === 'RightTop');
    image.size((err, value) => {
        // TODO: handle err
        let isPortrait = (value.height > value.width);
        overlayCopyrights(imgFilename, image, isPortrait);
    });
};

module.exports = addCopyright;<commit_msg>delete original file after adding copyright, plus cleanup<commit_after>'use strict';

var fs = require('fs');
var gm = require('gm').subClass({
    imageMagick: true
});

var getCrName = (imgFilename) => {
    return imgFilename.toLowerCase().replace('.jpg', '-cr.jpg');
};

var deleteOriginalFile = (imgFilename) => {
    fs.unlink(imgFilename, (err) => {
        if (err) {
            console.log(err);
        } else {
            console.log(imgFilename, '===> done deleting original');
        }
    });
};


var overlayCopyrights = (imgFilename, image, isPortrait) => {
    var imageCrName = getCrName(imgFilename);
    var imageCr;
    // var watermarkFile = 'img/Copyright640640-7percent.png';
    var sewnInUsa = 'img/sewnInUsa40-transparent.png';
    var hingmadeEtsyCom = 'img/hingmade-etsy-com.png';
    var hingmadeEtsyComGeo = isPortrait ? '-90+30' : '-90+10';
    image
        // .composite('img/Copyright.gif')
        .composite(sewnInUsa)
        .geometry('+10+10')
        .gravity('SouthEast')
        .write(imageCrName, function (err) {
            if (err) {
                console.log(err);
            } else {
                console.log(imgFilename, '===> done adding copyright text');
                imageCr = gm(imageCrName);
                imageCr
                    // .composite(watermarkFile)
                    .composite(hingmadeEtsyCom)
                    .geometry(hingmadeEtsyComGeo)
                    .gravity('North')
                    .write(imageCrName, function (err) {
                        if (err) {
                            console.log(err);
                        } else {
                            console.log(imgFilename, '===> done adding copyright watermark');
                            deleteOriginalFile(imgFilename);
                        }
                    }); 
            }
        });
};

var addCopyright = (imgFilename) => {
    let image = gm(imgFilename);
    image.size((err, value) => {
        // TODO: handle err
        let isPortrait = (value.height > value.width);
        overlayCopyrights(imgFilename, image, isPortrait);
    });
};

module.exports = addCopyright;
{'fraction_non_alphanumeric': 0.13424791768740812, 'fraction_numerical': 0.0102890739833415, 'mean_word_length': 1.7439516129032258, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, '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': '3583725', 'n_tokens_mistral': 1227, 'n_tokens_neox': 1162, 'n_words': 218}