Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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