首页 web服务器 正文
373

Resize images on server side

  • yiqingpeng
  • 2020-12-14
  • 0
  •  
Nodejs使用sharp库:

const sharp = require('sharp');
const fs = require('fs');
const directory = './images';

fs.readdirSync(directory).forEach(file => {
  sharp(`${directory}/${file}`)
    .resize(200, 100) // width, height
    .toFile(`${directory}/${file}-small.jpg`);
  });

还可以使用程序ImageMagick:

# macOS/Linux
convert flower.jpg -resize 300x200 flower-small.jpg

# Windows
magick convert flower.jpg -resize 300x200 flower-small.jpg


正在加载评论...