fs-thumbnail
Advanced tools
Comparing version 1.0.5 to 1.0.6
{ | ||
"name": "fs-thumbnail", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Library for generation of thumbnails based on file system paths.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -27,3 +27,4 @@ # fs-thumbnail | ||
# On Debian/Ubuntu | ||
# Make `ffmpeg` command available in your PATH. | ||
# E.g. on Debian and Ubuntu you can run: | ||
apt install ffmpeg | ||
@@ -44,4 +45,4 @@ ``` | ||
output: '/thumbnail/folder/thumbnail.jpg', | ||
size: 300, | ||
quality: 70, | ||
size: 300, // You can override the default size per thumbnail | ||
quality: 70, // You can override the default quality per thumbnail | ||
}) | ||
@@ -48,0 +49,0 @@ .then(thumbnailPath => { |
@@ -8,2 +8,4 @@ /** | ||
const path = require('path'); | ||
const fs = require('fs-extra'); | ||
const Promise = require('bluebird'); | ||
@@ -13,14 +15,31 @@ const ThumbGenerator = require('../lib/ThumbnailGenerator'); | ||
const input = path.join(__dirname, 'images', 'google-example.webp'); | ||
const output = path.join(__dirname, 'thumbs', 'google-example.thumb.jpg'); | ||
const inputDir = path.join(__dirname, 'files'); | ||
const outputDir = path.join(__dirname, 'thumbs'); | ||
thumbGen.getThumbnail({ | ||
path: input, | ||
output: output, | ||
size: 300, | ||
quality: 70, | ||
}) | ||
.then(thumbnailPath => { | ||
if (!thumbnailPath) console.log('Could not generate the thumbnail!'); | ||
else console.log(`Thumbnail generated! Find it here: ${thumbnailPath}`); | ||
}); | ||
const files = fs.readdirSync(inputDir); | ||
let i = 0; | ||
const createThumbPromise = (index) => { | ||
if (index >= files.length) return Promise.resolve(); | ||
const file = files[index]; | ||
const parsed = path.parse(file); | ||
const inPath = path.join(inputDir, file); | ||
const outPath = path.join(outputDir, `${parsed.name}.thumb.jpg`); | ||
return thumbGen.getThumbnail({ | ||
path: inPath, | ||
output: outPath, | ||
size: 300, | ||
quality: 70, | ||
}) | ||
.then(thumbnailPath => { | ||
if (!thumbnailPath) console.log(`${file}: Could not generate the thumbnail!`); | ||
else console.log(`${file}: Thumbnail generated! Find it here: ${outPath}`); | ||
}) | ||
.then(() => createThumbPromise(index + 1)); | ||
}; | ||
createThumbPromise(0) | ||
.catch(error => console.error(`Unexpected error occurred: ${error}`)); | ||
207571
9
211
52
3