Skip to content

Commit 5d2ed1b

Browse files
authored
Merge pull request #9 from Mitranim/master
added missing flatten option
2 parents 6fce4cd + 0d18fe3 commit 5d2ed1b

File tree

6 files changed

+51
-16
lines changed

6 files changed

+51
-16
lines changed

README.md

+35-14
Original file line numberDiff line numberDiff line change
@@ -60,86 +60,97 @@ gulp.task('default', function () {
6060

6161
#### options.width
6262

63-
Type: `Number`
63+
Type: `Number`
64+
6465
Default value: `0` (only if height is defined)
6566

6667
A number value that is passed as pixel or percentage value to imagemagick.
6768

6869

6970
#### options.height
7071

71-
Type: `Number`
72+
Type: `Number`
73+
7274
Default value: `0` (only if width is defined)
7375

7476
A number value that is passed as pixel or percentage value to imagemagick.
7577

7678

7779
#### options.upscale
7880

79-
Type: `Boolean`
81+
Type: `Boolean`
82+
8083
Default value: `false`
8184

8285
Determines whether images will be upscaled. If set to `false` (default), image will be copied instead of resized if it would be upscaled by resizing.
8386

8487

8588
#### options.crop
8689

87-
Type: `Boolean`
90+
Type: `Boolean`
91+
8892
Default value: `false`
8993

9094
Determines whether images will be cropped after resizing to exactly match `options.width` and `options.height`.
9195

9296

9397
#### options.gravity
9498

95-
Type: `String`
96-
Default value: `Center`
99+
Type: `String`
100+
101+
Default value: `Center`
97102
Possible values: `NorthWest`, `North`, `NorthEast`, `West`, `Center`, `East`, `SouthWest`, `South`, `SouthEast`
98103

99104
When cropping images this sets the image gravity. Doesn't have any effect, if `options.crop` is `false`.
100105

101106

102107
#### options.quality
103108

104-
Type: `Number`
109+
Type: `Number`
110+
105111
Default value: `1`
106112

107113
Determines the output quality of the resized image. Ranges from `0` (really bad) to `1` (almost lossless). Only applies to jpg images.
108114

109115

110116
#### options.format
111117

112-
Type: `String`
113-
Default value: Format of the input file
118+
Type: `String`
119+
120+
Default value: Format of the input file
114121
Possible values: `gif`, `png`, `jpeg` etc.
115122

116123
Override the output format of the processed file.
117124

118125
#### options.filter
119126

120-
Type: `String`
127+
Type: `String`
128+
121129
Possible values: `Point`, `Box`, `Triangle`, `Hermite`, `Hanning`, `Hamming`, `Blackman`, `Gaussian`, `Quadratic`, `Cubic`, `Catrom`, `Mitchell`, `Lanczos`, `Bessel`, `Sinc`
122130

123131
Set the filter to use when resizing (e.g. Catrom is very good for reduction, while hermite is good for enlargement).
124132

125133
#### options.sharpen
126134

127-
Type: `Boolean | String`
135+
Type: `Boolean | String`
136+
128137
Default value: `false`
129138

130139
Set to `true` to apply a slight unsharp mask after resizing.
131140
Or set a string to setup the unsharp. See [gm unsharp documentation](http://www.graphicsmagick.org/GraphicsMagick.html#details-unsharp). (e.g. '0.5x0.5+0.5+0.008')
132141

133142
#### options.samplingFactor
134143

135-
Type: `Array[Cr, Cb]`
144+
Type: `Array[Cr, Cb]`
145+
136146
Possible values: `[2, 2]` for 4:2:2, `[1, 1]` for 4:1:1
137147

138148
Define chroma subsampling
139149

140150
#### options.noProfile
141151

142-
Type: `Boolean`
152+
Type: `Boolean`
153+
143154
Default value: `false`
144155

145156
Set to `true` to enforce removal of all embedded profile data like icc, exif, iptc, xmp
@@ -149,21 +160,31 @@ cases where thumbnails are generated for web preview purposes. For details look
149160

150161
#### options.imageMagick
151162

152-
Type: `Boolean`
163+
Type: `Boolean`
164+
153165
Default value: `false`
154166

155167
Set to `true` when using ImageMagick instead of GraphicsMagick.
156168

157169
### options.background
158170

159171
Type: `String`
172+
160173
Possible values: `none` to keep transparency, `beige` to set beige background, `#888` for gray.
161174

162175
Define background color (default is white), for example when converting SVG images to PNGs.
163176
See [gm background documentation](http://www.graphicsmagick.org/GraphicsMagick.html#details-background)
164177

178+
### options.flatten
179+
180+
Type: `Boolean`
181+
182+
Default value: `false`
183+
184+
Combines image layers into one. Can be used for layered formats such as PNG. See [gm flatten documentation](http://www.graphicsmagick.org/GraphicsMagick.html#details-flatten).
165185

166186
## More Examples
187+
167188
```js
168189
// Converting from png to jpeg. No resizing.
169190
gulp.task('convert_png', function () {

gulpfile.js

+5
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,11 @@ resize("test/fixtures/hamburg.jpg", "noProfile", {
134134
noProfile: true
135135
});
136136

137+
resize("test/fixtures/wikipedia.png", "flatten", {
138+
format: "jpg",
139+
flatten: true
140+
});
141+
137142
gulp.task("image_resize", resizeTasks);
138143

139144
gulp.task("test", function(callback) {

index.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ module.exports = function imageResizer(_options) {
2121
noProfile : false,
2222
sharpen : false,
2323
imageMagick : false,
24-
format : null
24+
format : null,
25+
flatten : false
2526
});
2627

2728
return gm(function(gmfile, done) {
@@ -97,6 +98,10 @@ module.exports = function imageResizer(_options) {
9798
gmfile = gmfile.unsharp(options.sharpen);
9899
}
99100

101+
if (options.flatten) {
102+
gmfile = gmfile.flatten();
103+
}
104+
100105
if (options.background) {
101106
gmfile = gmfile.background(options.background);
102107
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "gulp-image-resize",
33
"description": "Resizing images made easy.",
4-
"version": "0.9.0",
4+
"version": "0.10.0",
55
"homepage": "https://github.com/scalableminds/gulp-image-resize",
66
"author": {
77
"name": "Norman Rzepka",

test/expected/flatten/wikipedia.jpg

25.9 KB
Loading

test/image_resize_test.js

+4
Original file line numberDiff line numberDiff line change
@@ -173,3 +173,7 @@ describe("noProfile", function () {
173173
});
174174
});
175175
});
176+
177+
describe("flatten", function () {
178+
it("should flatten the wikipedia image", createTests("flatten", "wikipedia.jpg"));
179+
});

0 commit comments

Comments
 (0)