feat: implement saveImageToFile to save downloaded images in a given directory

This commit is contained in:
xtrullor73
2024-05-25 00:43:04 -07:00
parent 739c18dd45
commit 7f3dd2c93a

View File

@@ -0,0 +1,19 @@
import path from 'path'; // Replace with your actual path
import downloadImageToFile from './downloadImageToFile.js';
export default async function saveImageToFile(imageUrl, outputDirectory) {
try {
// Create a safe file name
const imageName = path.basename(imageUrl); // This may need to be adjusted for unique naming
const savePath = path.join(outputDirectory, imageName);
// Use the updated function to download and get the path to the saved image
const savedImagePath = await downloadImageToFile(imageUrl, savePath);
console.log('Image saved to', savedImagePath);
return savedImagePath; // Return the saved image path for further use
} catch (error) {
console.error('Error writing image to file:', error);
throw error;
}
}