Skip to content

Commit

Permalink
implement setting page
Browse files Browse the repository at this point in the history
  • Loading branch information
zmcx16 committed Jun 6, 2020
1 parent 78ebbe3 commit 191cb53
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 6 deletions.
14 changes: 14 additions & 0 deletions core/src/core_def.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ class CoreTaskKey:
SOURCE = 'src'
TYPE = 'type'
EFFECTS = 'effects'
OUTPUT = 'output'
TASK_ID = 'task_id'
SHOW = 'show'
TASK = 'task'
Expand All @@ -48,6 +49,19 @@ class CoreTaskCmdKey:
STOP_TASK = 'stop_task'


class OutputKey:
FORMAT = 'format'

# format
PNG = 'PNG'
JPEG = 'JPEG'
BMP = 'BMP'

COMPRESS_LEVEL = 'compress_level'
QUALITY = 'quality'
OPTIMIZE = 'optimize'


class BlendKey:
# config
OPACITY = 'opacity'
Expand Down
20 changes: 16 additions & 4 deletions core/src/mpcore.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from image_enhance import ImageEnhance
from blend import Blend
from levels import Levels
from core_def import CoreReturn, CoreModeKey, CoreTaskKey, CoreTaskCmdKey
from core_def import CoreReturn, CoreModeKey, CoreTaskKey, CoreTaskCmdKey, OutputKey


class MangaPrettierCore(object):
Expand Down Expand Up @@ -86,6 +86,7 @@ def __run_task(self, param, task_id):
output_folder_name = datetime.now().strftime("%Y%m%d-%H%M%S")
images_path = param[CoreTaskKey.PARAMETER][CoreTaskKey.IMAGES_PATH]
effects = param[CoreTaskKey.PARAMETER][CoreTaskKey.EFFECTS]
output = param[CoreTaskKey.PARAMETER][CoreTaskKey.OUTPUT]

for image_i in range(len(images_path)):

Expand Down Expand Up @@ -113,9 +114,20 @@ def __run_task(self, param, task_id):
mode = MangaPrettierCore.ModeDict[config[CoreTaskKey.TYPE]]
image = mode.run(image, config, False).copy()

image = Image.fromarray(image).convert('RGB')
#image.save(os.path.splitext(output_path)[0]+'.png', format='png')
image.save(os.path.splitext(output_path)[0] + '.jpg', format='jpeg', quality=95, optimize=True)
if output[OutputKey.FORMAT] == OutputKey.PNG:
image = Image.fromarray(image).convert('RGBA')
image.save(os.path.splitext(output_path)[0]+'.png', format='png',
compress_level=output[OutputKey.COMPRESS_LEVEL], optimize=output[OutputKey.OPTIMIZE])
elif output[OutputKey.FORMAT] == OutputKey.JPEG:
image = Image.fromarray(image).convert('RGB')
image.save(os.path.splitext(output_path)[0] + '.jpg', format='jpeg',
quality=output[OutputKey.QUALITY], optimize=output[OutputKey.OPTIMIZE])
elif output[OutputKey.FORMAT] == OutputKey.BMP:
image = Image.fromarray(image).convert('RGB')
image.save(os.path.splitext(output_path)[0] + '.bmp', format='bmp')
else:
image = Image.fromarray(image).convert('RGB')
image.save(os.path.splitext(output_path)[0] + '.jpg', format='jpeg')

# --------------------

Expand Down
5 changes: 3 additions & 2 deletions gui/src/components/settingPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ function SettingPanel({ settingPanelRef, appAPI, filesPanelAPI, previewImagePane
// run task
const task_heartbeat = useRef(0)

const runTask = (imgs_path, effects) => {
const runTask = (imgs_path, effects, output) => {

setProgressBar(0)

Expand All @@ -196,6 +196,7 @@ function SettingPanel({ settingPanelRef, appAPI, filesPanelAPI, previewImagePane
task: 'batch',
param: {
imgs_path: imgs_path,
output: output,
effects: effects
}
}
Expand Down Expand Up @@ -351,7 +352,7 @@ function SettingPanel({ settingPanelRef, appAPI, filesPanelAPI, previewImagePane
taskRunningRef.current = !taskRunningRef.current
setTaskRunningUI()
if (taskRunningRef.current) {
runTask(imgs_path, effects)
runTask(imgs_path, effects, config['output'])
}
}

Expand Down

0 comments on commit 191cb53

Please sign in to comment.