Created
July 2, 2014 13:42
-
-
Save sgrebnov/a83148b6862b090ea002 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function copyMrtImage(src, dest){ | |
var srcDir = path.dirname(src), | |
srcExt = path.extname(src), | |
srcFileName = path.basename(src, srcExt); | |
var destDir = path.dirname(dest), | |
destExt = path.extname(dest), | |
destFileName = path.basename(dest, destExt); | |
// all MRT images: logo.png, logo.scale-100.png, logo.scale-200.png, etc | |
var images = fs.readdirSync(srcDir).filter(function(e) { | |
return e.match('^'+srcFileName + '(.scale-[0-9]+)?' + srcExt); | |
}); | |
// warn if no images found | |
if (images.length == 0) { | |
events.emit('warn', 'Image not found: ' + src); | |
return; | |
} | |
// copy images with new name but keeping scale suffix | |
images.forEach(function(img) { | |
var scale = path.extname(path.basename(img, srcExt)), | |
imgSrc = path.join(srcDir, img), | |
imgDest = path.join(destDir, destFileName+scale+destExt); | |
events.emit('verbose', 'Copying image from ' + imgSrc + ' to ' + imgDest); | |
shell.cp('-f', imgSrc, imgDest); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment