added transform support for exporting + tweaks and cleanup...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2020-10-31 02:10:27 +03:00
parent 5c73431299
commit d4ca5ba455
2 changed files with 31 additions and 32 deletions

View File

@ -2131,7 +2131,9 @@ var FileSystemWriterActions = actions.Actions({
// XXX make this dependant on max_size.... // XXX make this dependant on max_size....
include_orig = include_orig || true include_orig = include_orig || true
var resize = max_size && this.makeResizedImage // XXX get value from settings...
var resize = max_size
&& this.makeResizedImage
// clear/backup target... // clear/backup target...
clean_target_dir = clean_target_dir === undefined ? clean_target_dir = clean_target_dir === undefined ?
@ -2252,18 +2254,17 @@ var FileSystemWriterActions = actions.Actions({
res res
: max : max
return true } return true }
// skip and remove... // skip and remove...
delete previews[res] delete previews[res]
replace_orig = true }) replace_orig = true })
// get paths... // get paths...
.map(function(res){ .map(function(res){
return res != max ? if(res != max){
decodeURI(previews[res]) return decodeURI(previews[res]) }
// NOTE: we will skip including the preview // NOTE: we will skip including the preview
// we are using as the primary image to // we are using as the primary image to
// save space... // save space...
: null }) delete previews[res] })
// add primary image (copy)... // add primary image (copy)...
// XXX check if any of the previews/main images // XXX check if any of the previews/main images
// matches the size and copy instead of resize... // matches the size and copy instead of resize...
@ -2327,7 +2328,12 @@ var FileSystemWriterActions = actions.Actions({
resize resize
&& include_orig && include_orig
&& queue && queue
.push(this.makeResizedImage(gids, max_size, path, { logger })) .push(this.makeResizedImage(gids, max_size, path, {
// NOTE: we do not transform here so as to keep
// the index as-is, minimizing changes...
transform: false,
logger,
}))
// index... // index...
var index = this.prepareIndexForWrite(json, true) var index = this.prepareIndexForWrite(json, true)

View File

@ -170,7 +170,8 @@ var SharpActions = actions.Actions({
transform: ..., transform: ...,
crop: ..., crop: ...,
logger: ... timestamp: ...,
logger: ...,
, } , }
@ -220,26 +221,24 @@ var SharpActions = actions.Actions({
overwrite, overwrite,
// transformations... // transformations...
// XXX not implemented...
transform, transform,
// XXX not implemented... // XXX not implemented...
crop, crop,
timestamp,
logger, logger,
} = options } = options
// defaults... // defaults...
pattern = pattern || '%n' pattern = pattern || '%n'
/* XXX
transform = transform === undefined ? transform = transform === undefined ?
true true
: transform : transform
//*/ timestamp = timestamp || Date.timeStamp()
logger = logger || this.logger logger = logger || this.logger
logger = logger && logger.push('Resize') logger = logger && logger.push('Resize')
// backup... // backup...
// XXX make backup name pattern configurable... // XXX make backup name pattern configurable...
var timestamp = Date.timeStamp()
var backupName = function(to){ var backupName = function(to){
var i = 0 var i = 0
while(fse.existsSync(`${to}.${timestamp}.bak`+ (i || ''))){ while(fse.existsSync(`${to}.${timestamp}.bak`+ (i || ''))){
@ -301,21 +300,17 @@ var SharpActions = actions.Actions({
.clone() .clone()
// handle transform (.orientation / .flip) and .crop... // handle transform (.orientation / .flip) and .crop...
.run(function(){ .run(function(){
var img_data = that.images[gid]
if(transform && (img_data.orientation || img_data.flipped)){
img_data.orientation
&& this.rotate(img_data.orientation)
img_data.flipped
&& img_data.flipped.includes('horizontal')
&& this.flip() }
img_data.flipped
&& img_data.flipped.includes('vertical')
&& this.flop()
// XXX // XXX
if(transform || crop){
throw new Error('.makeResizedImage(..): '
+[
transform ? 'transform' : [],
crop ? 'crop' : [],
].flat().join(' and ')
+' not implemented...') }
// XXX need clear spec defining what
// order transforms are applied
// and in which coordinates we
// crop (i.e. pre/post transform)...
if(transform){
// XXX
}
if(crop){ if(crop){
// XXX // XXX
} }
@ -444,8 +439,7 @@ var SharpActions = actions.Actions({
img.orientation = o.orientation img.orientation = o.orientation
img.flipped = o.flipped img.flipped = o.flipped
that.markChanged('images', [data.gid]) that.markChanged('images', [data.gid]) }
}
// NOTE: this will handle both 'queue' and 'resolved' statuses... // NOTE: this will handle both 'queue' and 'resolved' statuses...
logger && logger &&
@ -482,8 +476,7 @@ var SharpActions = actions.Actions({
} }
data == 'completed' ? data == 'completed' ?
resolve() resolve()
: post_handler(err, data) } : post_handler(err, data) } }) }))
}) }))
// now do the work (sync)... // now do the work (sync)...
} else { } else {