Skip to content

Instantly share code, notes, and snippets.

@derpycoder
Last active January 27, 2023 17:22
Show Gist options
  • Save derpycoder/658cb3c89420d332fbc4010404a012c0 to your computer and use it in GitHub Desktop.
Save derpycoder/658cb3c89420d332fbc4010404a012c0 to your computer and use it in GitHub Desktop.
Collection of Tasks to Crop, Resize & Compress Images
---
version: "3"
tasks:
convert:
dir: "{{.USER_WORKING_DIR}}"
desc: Convert Animated PNGs to Gifs
summary: |
task gif:convert
cmds:
- for file in ./*.png; do ffmpeg -i "$file" -filter_complex "[0:v] scale=256:256, split [a][b]; [a] palettegen=reserve_transparent=on:transparency_color=ffffff [p]; [b][p] paletteuse" "${file%.*}.gif"; done
sources:
- ./*.png
generates:
- ./*.gif
compress:
dir: "{{.USER_WORKING_DIR}}"
desc: Compress Gifs
summary: |
task gif:compress
vars:
FOLDER: "gif"
cmds:
- for file in ./*.gif; do convert "$file" -coalesce -fuzz 5% -layers Optimize +map "${file%.*}.min.gif"; done
- mkdir -p {{.FOLDER}}
- mv *.min.gif ./{{.FOLDER}}
sources:
- ./*.gif
generates:
- ./{{.FOLDER}}/*.min.gif
---
version: "3"
tasks:
compress:
dir: "{{.USER_WORKING_DIR}}"
aliases: [c]
desc: Used to Compress WebP Images.
summary: |
task webp:compress
task webp:compress -- 90 // Specify Quality
vars:
QUALITY: "{{default 80 .CLI_ARGS}}"
FOLDER: "webp"
cmds:
- mkdir -p {{.FOLDER}}
- defer: mv *.webp ./{{.FOLDER}}
- for file in ./*.*; do cwebp -mt -q {{.QUALITY}} "$file" -o "${file%.*}.webp"; done
sources:
- ./*.png
generates:
- ./{{.FOLDER}}/*.webp
scale:
dir: "{{.USER_WORKING_DIR}}"
aliases: [s]
desc: Used to Compress WebP Images.
summary: |
task webp:scale
task webp:scale -- 2000 // Specify Scale
QUALITY=70 task webp:s -- 1000 // Specify Quality & Scale
vars:
WIDTH: "{{default 2000 .CLI_ARGS}}"
QUALITY: "{{default 80 .QUALITY}}"
FOLDER: "webp"
cmds:
- for file in ./*.*; do cwebp -q {{.QUALITY}} "$file" -o "${file%.*}.webp"; done
- mkdir -p {{.FOLDER}}
- mv *.webp ./{{.FOLDER}}
sources:
- ./*.png
generates:
- ./{{.FOLDER}}/*.webp
crop:
dir: "{{.USER_WORKING_DIR}}"
desc: Used to Crop WebP Images.
summary: |
task webp:crop -- 1000 1000
cmds:
- for file in ./*; do cwebp -mt -q 80 -crop 0 0 {{.CLI_ARGS}} "$file" -o "${file%.*}.webp"; done
---
version: "3"
env:
QUALITY: 80
includes:
webp: ./Taskfile.webp.yml
gif: ./Taskfile.gif.yml
tasks:
update:
desc: Update all installed dependencies
summary: |
task update
cmds:
- brew update
- brew upgrade
- brew cleanup
install:
desc: Install all dependencies using HomeBrew
summary: |
Must have Task installed (brew install go-task)
task setup
cmds:
- task: update
- brew install ffmpeg
- brew install imagemagick
- brew install webp
create:
desc: Creates a Taskfile.yml
summary: |
task create -- gif
cmds:
- echo --- > Taskfile.{{.CLI_ARGS}}.yml
@derpycoder
Copy link
Author

> brew install go-task
...
> cd subdirectory
> task webp:compress
...
> cd another_sub_directory
> task gif:convert task gif:compress

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment