Created
January 20, 2019 13:36
-
-
Save pirosuke/ef73f3770f3c017c9c86392caf4320d7 to your computer and use it in GitHub Desktop.
An Example To Resize Image Files Using OpenCV And Node.js
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
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