HerrHase 2 years ago
parent b213bf74ed
commit 4ae23d8f63

@ -4,6 +4,7 @@ const sharp = require('sharp')
const mkdirp = require('mkdirp') const mkdirp = require('mkdirp')
const crypto = require('crypto') const crypto = require('crypto')
const slugify = require('slugify') const slugify = require('slugify')
const assign = require('assign-deep')
const configStore = require('./../config.js') const configStore = require('./../config.js')
@ -142,16 +143,34 @@ class Media {
*/ */
_writeFile(file, process, options) { _writeFile(file, process, options) {
// resize without options and with options // if sizes have height or width with no optional parameters then check for merge of options
if (file.sizes && Object.getOwnPropertyNames(options).length === 0 && Object.getOwnPropertyNames(file.sizes).length > 0) { if (file.sizes &&
(((!file.sizes.height || !file.sizes.width) && Object.getOwnPropertyNames(file.sizes).length === 1) ||
(file.sizes.height && file.sizes.width && Object.getOwnPropertyNames(file.sizes).length === 2))) {
process.resize(this._mergeOptions(file.sizes, options))
// if already options in sizes ignore options
} else if (file.sizes) {
process.resize(file.sizes) process.resize(file.sizes)
} else if (file.sizes && Object.getOwnPropertyNames(options).length > 0 && Object.getOwnPropertyNames(file.sizes).length > 0) {
process.resize(file.sizes, options)
} }
process.toFile(configStore.get('destination') + file.path) process.toFile(configStore.get('destination') + file.path)
} }
/**
* if options are exists merge them with sizes
*
* @param {object} sizes
* @param {Object} options
*/
_mergeOptions(sizes, options) {
if (Object.getOwnPropertyNames(options).length > 0) {
sizes = assign(options, sizes)
}
return sizes
}
/** /**
* generate destination path from hash of file * generate destination path from hash of file
* *

Loading…
Cancel
Save