krouzek:galerie

Do package.json přidat

  "type": "module",

Procházení filesystému

import { readdir } from 'node:fs/promises';
 
/*
const sharp = require('sharp')
 
console.log('Resizing')
 
sharp('alps.jpg')
  .resize(1200, 1200)
  .rotate(10, {background: "#ff0000"})
  .toFile('output.jpg', function(err) {
  });
*/
 
try {
  const photoRoot = await readdir('photos');
  for (const photoDirName of photoRoot){
    console.log(photoDirName);
    // Jednotliva galerie
    const photoDir = await readdir(`photos/${photoDirName}`)
 
      for (const photoName of photoDir){
        if(photoName.toLowerCase().endsWith('.jpg')){
          console.log(` photos/${photoDirName}/${photoName}`)
        }
      }
 
  }
} catch (err) {
  console.error(err);
} 
  • krouzek/galerie.txt
  • Poslední úprava: 2023/11/15 20:54
  • autor: 127.0.0.1