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....
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...
clean_target_dir = clean_target_dir === undefined ?
@ -2252,18 +2254,17 @@ var FileSystemWriterActions = actions.Actions({
res
: max
return true }
// skip and remove...
delete previews[res]
replace_orig = true })
// get paths...
.map(function(res){
return res != max ?
decodeURI(previews[res])
if(res != max){
return decodeURI(previews[res]) }
// NOTE: we will skip including the preview
// we are using as the primary image to
// save space...
: null })
delete previews[res] })
// add primary image (copy)...
// XXX check if any of the previews/main images
// matches the size and copy instead of resize...
@ -2327,7 +2328,12 @@ var FileSystemWriterActions = actions.Actions({
resize
&& include_orig
&& 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...
var index = this.prepareIndexForWrite(json, true)

View File

@ -170,7 +170,8 @@ var SharpActions = actions.Actions({
transform: ...,
crop: ...,
logger: ...
timestamp: ...,
logger: ...,
, }
@ -220,26 +221,24 @@ var SharpActions = actions.Actions({
overwrite,
// transformations...
// XXX not implemented...
transform,
// XXX not implemented...
crop,
timestamp,
logger,
} = options
// defaults...
pattern = pattern || '%n'
/* XXX
transform = transform === undefined ?
true
: transform
//*/
timestamp = timestamp || Date.timeStamp()
logger = logger || this.logger
logger = logger && logger.push('Resize')
// backup...
// XXX make backup name pattern configurable...
var timestamp = Date.timeStamp()
var backupName = function(to){
var i = 0
while(fse.existsSync(`${to}.${timestamp}.bak`+ (i || ''))){
@ -301,21 +300,17 @@ var SharpActions = actions.Actions({
.clone()
// handle transform (.orientation / .flip) and .crop...
.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
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){
// XXX
}
@ -444,8 +439,7 @@ var SharpActions = actions.Actions({
img.orientation = o.orientation
img.flipped = o.flipped
that.markChanged('images', [data.gid])
}
that.markChanged('images', [data.gid]) }
// NOTE: this will handle both 'queue' and 'resolved' statuses...
logger &&
@ -482,8 +476,7 @@ var SharpActions = actions.Actions({
}
data == 'completed' ?
resolve()
: post_handler(err, data) }
}) }))
: post_handler(err, data) } }) }))
// now do the work (sync)...
} else {