项目作者: fjlaubscher

项目描述 :
a super simple nodejs image resizer
高级语言: JavaScript
项目地址: git://github.com/fjlaubscher/node-imager.git
创建时间: 2016-03-20T09:09:14Z
项目社区:https://github.com/fjlaubscher/node-imager

开源协议:MIT License

下载


node-imager

a super simple nodejs image resizer.
resize files on disk or over http / https

https://nodei.co/npm/node-imager.png?downloads=true&downloadRank=true&stars=true

Prerequisites

installation

  1. $ npm install node-imager --save

usage

basic usage example:

  1. const express = require('express');
  2. const imager = require('node-imager');
  3. const app = express();
  4. app.get('/imager/', (req, res) => {
  5. // node-imager will try to find this image relative the root of your application
  6. // absolute file paths or urls work too
  7. const url = 'http://i.imgur.com/1KDwL1M.png';
  8. const options = {
  9. width: 500,
  10. height: 500,
  11. format: 'c',
  12. url
  13. };
  14. // crop image
  15. imager.resizeWith(options, (contentType, imageBuffer) => {
  16. res.setHeader('Content-Type', contentType);
  17. res.send(imageBuffer);
  18. });
  19. });
  20. app.listen(3000);

api

  1. option (String): 'c' - crops the image from the center outwards.
  2. '' - for normal resizing
  3. width (Number): desired width
  4. height (Number): desired height
  5. url (String): can be relative path or remote file on the web
  6. 'images/test.png'
  7. 'http://i.imgur.com/1KDwL1M.png' --important to prefix with 'http://'
  8. next: callback function
  9. (contentType, imageBuffer) => { }
  1. resize(option, width, height, url, callback);

or

  1. const options = {
  2. width: 500,
  3. height: 500,
  4. format: 'c',
  5. url
  6. };
  7. resizeWith(options, callback);