From af74b7047b86e37fa86cc54b8e09bb93b5523575 Mon Sep 17 00:00:00 2001 From: Mikael Finstad Date: Mon, 14 Aug 2017 14:37:57 +0200 Subject: [PATCH] Implement select img format --- src/capture-frame.js | 8 +++----- src/renderer.jsx | 18 ++++++++++++++++-- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/src/capture-frame.js b/src/capture-frame.js index aa4a38ab..9bc3759a 100644 --- a/src/capture-frame.js +++ b/src/capture-frame.js @@ -7,9 +7,7 @@ const util = require('./util'); bluebird.promisifyAll(fs); -function getFrameFromVideo(video) { - const format = 'jpeg'; - +function getFrameFromVideo(video, format) { const canvas = document.createElement('canvas'); canvas.width = video.videoWidth; canvas.height = video.videoHeight; @@ -21,8 +19,8 @@ function getFrameFromVideo(video) { return strongDataUri.decode(dataUri); } -function captureFrame(customOutDir, filePath, video, currentTime) { - const buf = getFrameFromVideo(video); +function captureFrame(customOutDir, filePath, video, currentTime, captureFormat) { + const buf = getFrameFromVideo(video, captureFormat); const ext = mime.extension(buf.mimetype); const time = util.formatDuration(currentTime); diff --git a/src/renderer.jsx b/src/renderer.jsx index f445e294..44f5841f 100644 --- a/src/renderer.jsx +++ b/src/renderer.jsx @@ -85,6 +85,7 @@ class App extends React.Component { cutStartTime: 0, cutEndTime: undefined, fileFormat: undefined, + captureFormat: 'jpeg', }; this.state = _.cloneDeep(defaultState); @@ -180,6 +181,11 @@ class App extends React.Component { return (this.state.filePath || '').replace(/#/g, '%23'); } + toggleCaptureFormat() { + const isPng = this.state.captureFormat === 'png'; + this.setState({ captureFormat: isPng ? 'jpeg' : 'png' }); + } + jumpCutStart() { seekAbs(this.state.cutStartTime); } @@ -260,8 +266,10 @@ class App extends React.Component { const filePath = this.state.filePath; const outputDir = this.state.outputDir; const currentTime = this.state.currentTime; + const captureFormat = this.state.captureFormat; if (!filePath) return; - captureFrame(outputDir, filePath, getVideo(), currentTime).catch(err => alert(err)); + captureFrame(outputDir, filePath, getVideo(), currentTime, captureFormat) + .catch(err => alert(err)); } toggleHelp() { @@ -367,7 +375,7 @@ class App extends React.Component {
{renderHelpSheet(this.state.helpVisible)}