Skip to content

Commit

Permalink
images: ability to pass jpeg options for sharp engine
Browse files Browse the repository at this point in the history
  • Loading branch information
enzy committed Oct 3, 2017
1 parent 0a96f8c commit 286ee75
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
1 change: 1 addition & 0 deletions docs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ All options can be overridden in `mango.local.yaml` (or `mango.local.json`) file
* `src` - string (glob) source of images
* `sizes` - array of widths (int)
* `aspectRatio` - aspect ratio of image on output (float = width/height), if undefined or false aspect ratio of image is used
* `options` - [output options](http://sharp.dimens.io/en/stable/api-output/#jpeg) for [sharp](http://sharp.dimens.io/en/stable/) resizing engine

---

Expand Down
5 changes: 3 additions & 2 deletions lib/tasks/images.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ module.exports = function(gulp, config) {
fileClone.path = path.join(name.dir, name.name + '-' + size + name.ext)
fileClone.imageTransform = {
width: size,
height: file.imageData.aspectRatio ? Math.ceil(size/file.imageData.aspectRatio) : null
height: file.imageData.aspectRatio ? Math.ceil(size/file.imageData.aspectRatio) : null,
options: file.imageData.options || {},
}
this.push(fileClone)
}
Expand All @@ -84,7 +85,7 @@ module.exports = function(gulp, config) {
var transformStream = new stream.Transform({objectMode: true});
transformStream._transform = function (file, encoding, callback) {
if(file.imageTransform) {
sharp(file.contents).resize(file.imageTransform.width, file.imageTransform.height).withoutEnlargement().toBuffer(function (err, buffer, info) {
sharp(file.contents).resize(file.imageTransform.width, file.imageTransform.height).withoutEnlargement().jpeg(file.imageTransform.options).toBuffer(function (err, buffer, info) {
if(err) console.error(err)
file.contents = buffer
callback(null, file)
Expand Down

0 comments on commit 286ee75

Please sign in to comment.