Skip to content

Instantly share code, notes, and snippets.

@pirosuke
Created January 20, 2019 13:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pirosuke/ef73f3770f3c017c9c86392caf4320d7 to your computer and use it in GitHub Desktop.
Save pirosuke/ef73f3770f3c017c9c86392caf4320d7 to your computer and use it in GitHub Desktop.
An Example To Resize Image Files Using OpenCV And Node.js
const path = require('path');
const fs = require('fs');
const cv = require('opencv4nodejs');
function resizeImagesToMax(srcDirPath, destDirPath, maxWidthHeight) {
const srcFileList = fs.readdirSync(srcDirPath);
for (const srcFileName of srcFileList) {
if (!srcFileName.endsWith('.JPG')) {
continue;
}
console.log('Processing ', srcFileName, '...');
const imgMat = cv.imread(path.join(srcDirPath, srcFileName));
const imgMatConverted = imgMat.resizeToMax(maxWidthHeight);
cv.imwrite(path.join(destDirPath, srcFileName), imgMatConverted);
}
}
function main() {
const srcDirPath = 'SOURCE_DIRECTORY_PATH';
const destDirPath = 'DEST_DIRECTORY_PATH';
resizeImagesToMax(srcDirPath, destDirPath, 100);
}
main();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment