Skip to content

Commit

Permalink
feat: add gif support (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
antonreshetov authored Nov 29, 2021
1 parent f502e7b commit e697da3
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
"dependencies": {
"electron-store": "^8.0.1",
"fs-extra": "^10.0.0",
"gifsicle": "^5.3.0",
"junk": "3.1.0",
"mime-types": "^2.1.34",
"mozjpeg": "^7.0.0",
Expand Down
19 changes: 19 additions & 0 deletions src/main/image-compressor.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { ensureDirSync, readFile, writeFile, readdir } = require('fs-extra')
const { execFile } = require('child_process')
const mozjpeg = require('mozjpeg')
const pngquant = require('pngquant-bin')
const gifsicle = require('gifsicle')
const svg = require('svgo')
const junk = require('junk')
const mime = require('mime-types')
Expand All @@ -18,6 +19,7 @@ const MIME_TYPE_ENUM = {
jpg: 'image/jpeg',
png: 'image/png',
svg: 'image/svg+xml',
gif: 'image/gif',
folder: ''
}

Expand Down Expand Up @@ -152,6 +154,23 @@ class ImageOptimizer {
break
}

case MIME_TYPE_ENUM.gif: {
execFile(gifsicle, ['-o', output, file.path], err => {
if (err) {
console.log(err)
reject(err)
}

const compressedSize = getFileSize(output)
context.webContents.send(
'file-complete',
this.#formatOutputData(file, originalSize, compressedSize)
)
resolve()
})
break
}

case MIME_TYPE_ENUM.svg: {
readFile(file.path, (err, buffer) => {
if (err) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ module.exports = context => {
V8: ${process.versions.v8}
OS: ${os.type()} ${os.arch()} ${os.release()}
©2019-${year} Anton Reshetov <[email protected]>
©2021-${year} Anton Reshetov <[email protected]>
`
})
}
Expand Down
2 changes: 1 addition & 1 deletion src/renderer/components/AppDragArea.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div class="hero">
<AppLogo />
<h2>Drag files or folder here</h2>
<p>support only JPG, PNG and SVG</p>
<p>support only JPG, PNG, GIF and SVG</p>
</div>
</div>
</template>
Expand Down
9 changes: 9 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -5027,6 +5027,15 @@ getpass@^0.1.1:
dependencies:
assert-plus "^1.0.0"

[email protected]:
version "5.3.0"
resolved "https://registry.yarnpkg.com/gifsicle/-/gifsicle-5.3.0.tgz#499713c6f1e89ebbc3630da3a74fdb4697913b4e"
integrity sha512-FJTpgdj1Ow/FITB7SVza5HlzXa+/lqEY0tHQazAJbuAdvyJtkH4wIdsR2K414oaTwRXHFLLF+tYbipj+OpYg+Q==
dependencies:
bin-build "^3.0.0"
bin-wrapper "^4.0.0"
execa "^5.0.0"

git-clone@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/git-clone/-/git-clone-0.1.0.tgz#0d76163778093aef7f1c30238f2a9ef3f07a2eb9"
Expand Down

0 comments on commit e697da3

Please sign in to comment.