项目作者: zekth

项目描述 :
Gulp task for processing images
高级语言: JavaScript
项目地址: git://github.com/zekth/gulp-image-process.git
创建时间: 2018-07-26T07:40:15Z
项目社区:https://github.com/zekth/gulp-image-process

开源协议:MIT License

下载


gulp-image-process

A Gulp task for processing images base on sharp for its speed, features and easiness of deployement.

Installation

  1. npm install gulp gulp-image-process --save-dev

Usage

  1. 'use strict'
  2. const imageProcess = require('gulp-image-process')
  3. const gulp = require('gulp')
  4. const path = require('path')
  5. gulp.task('images', () => {
  6. let imageFolder = path.resolve('test', 'ressources', 'src', '*.jpg')
  7. return gulp
  8. .src(imageFolder)
  9. .pipe(
  10. imageProcess({
  11. verboseLogging: true,
  12. progressive:true,
  13. width:200,
  14. heigth:200,
  15. output: 'webp',
  16. ignoreRatio:false,
  17. multipleResize: [150,300],
  18. watermark: {
  19. filePath: 'test/ressources/src/watermark.png',
  20. position: 'north',
  21. maxSize: 20,
  22. margin: 30
  23. }
  24. })
  25. )
  26. .pipe(gulp.dest(path.resolve('test', 'result')))
  27. })

API

options

options.output

Type: String

Default: false

Force the output format. Possible values jpeg|png|webp

options.quality

Type: Number

Default: 100

Quality of the output image. From 0 to 100.

options.verboseLogging

Type: Boolean

Default: false

Enable the verbose logging.

options.multipleResize

Type: Array<Number>

Default: false

Will perform multiple resize of the values passed in parameter. Resizes are made on the rendered images, for example it will resize the image with the watermark.

options.keepMetadata

Type: Boolean

Default: false

Keep the EXIF file on the output file.

options.progressive

Type: Boolean

Default: false

Output using progressive scan. Only available for jpeg output.

options.ignoreRatio

Type: Boolean

Default: false

While resizing it will ignore the base ratio of the image with a crop.

options.watermark

Type: Object

Default: null

options.watermark.filePath

Type: String

Default: ''

Is Mandatory: True

Path of the watermark file.

options.watermark.position

Type: String

Default: ''

Is Mandatory: True

Position of the watermark on the image.

Possible values:

  1. center
  2. north
  3. south
  4. west
  5. east
  6. northwest
  7. northeast
  8. southwest
  9. southeast

Little reminder:

  1. northwest north northeast
  2. \ | /
  3. \ | /
  4. west ---- center ---- east
  5. / | \
  6. / | \
  7. southwest south southeast
options.watermark.maxSize

Type: Number

Default: -1

Max Size in Percent of the watermark on the image. If default value is used, the watermark will get its original size.

options.watermark.margin

Type: Number

Default: 0

Margin of the watermark from the border of the image. Applied to all coordinates. Similar of css attribute margin:<value>px;

TODO

  • Unit tests :v
  • Optimization prompt (diff input / ouput size)

License

MIT License