gulp-imgconv
A gulp plugin to convert images (format conversion, resizing, cutting in/out, watermarking etc.) for distribution or batch image processing
Installation
npm install gulp-imgconv --save-dev
Change Log
- v0.9.x: refactored pipeline construction to Fluent-API (or method-chainning model)
Usage
- DISTRIBUTION: resize all images under
src/
, cutin with a round shape, add a watermark, sharpen, grascale, boolean with a 5-pointed star and save them todst/
in PNG format
const gulp = gic = ; exports { gulp ; };
Click below links to see the conversion effect
- PROCESSING: resize the original images in
src/
to width = 800, sharpen, grayscale them and save todst/
in corresponding formats (SVG, GIF -> PNG, otherwise the original format)
const gulp = gic = ; exports {gulp ; };
API
The only argument is a pipeline in Array design, and there're 2 basic functions:
- resize(widith?: number, height?: number, opts?: {[k: string]: any}) - now a direct mapping to Sharp's
resize
function- Where
width
andheight
are size to resize to; when any parameter is ommitted, its value will be determined byfit
option. Please refer toresizeOptsHelper
object of this package to learn how to make up a correct opts object.
- Where
- toFormat(fmt: string, opts?: {[k: string]: any})
- Where
fmt
is the format to convert to (right now supports jpeg, png, tiff and webp). There are quite a few option choices for each format, please find more details from sharp official document
- Where
And 3 overlaying related featured functions inspired by my past experiences:
- cutin/cutout/watermark(src: Buffer | string, opts?: {[k: string]: any}) - an encapsulation of Sharp's
composite
function- Where
src
is either the svg/png file name (in string) or the data (in Buffer) to overlay upon the original image, and you can learn how to construct the basicopts
argument with the help ofcompositeOptsHelper
, or read sharp official document to comprehensively understand the exact meaning of each option.
- Where
begin()
and ended by commit()
.
To construct this pipeline array, you can use chained method calling started by sharp are supported with the same function prototype, please feel free to use like what I did in the test gulpfile.js
file:
Moreover, almost all other transformation related functions of - extend, extract, trim
- rotate, flip, flop
- sharpen, median, blur
- flatten, gamma, negate, linear, normalize, convolve, threshould, recomb, modulate
- tint, grayscale, toColorspace
- removeAlpha, ensureAlpha, extractChannel, joinChannel, bandbool
- composite, boolean
Thanks
Special gratitude to sharp and other dependencies
Author
tibetty xihua.duan@gmail.com