Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ericdriussi/hugo-image-optimizer
Quick and dirty image optimizer for Hugo based websites
https://github.com/ericdriussi/hugo-image-optimizer
go gohugo golang hugo
Last synced: 3 months ago
JSON representation
Quick and dirty image optimizer for Hugo based websites
- Host: GitHub
- URL: https://github.com/ericdriussi/hugo-image-optimizer
- Owner: EricDriussi
- License: gpl-3.0
- Created: 2023-01-28T12:04:03.000Z (about 2 years ago)
- Default Branch: master
- Last Pushed: 2023-07-15T18:07:49.000Z (over 1 year ago)
- Last Synced: 2024-10-14T18:41:35.599Z (4 months ago)
- Topics: go, gohugo, golang, hugo
- Language: Go
- Homepage:
- Size: 265 KB
- Stars: 7
- Watchers: 1
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Hugo Image Optimizer
> Quick and dirty image optimizer for Hugo based websites
>
> Removes all unused images, converts the rest (png, jpg and gifs) to a compressed .webp format and updates all references in your posts.## Use Case
I often screw around with my blog, adding and changing images without much attention to size, weight or format.
As a result, I end up with a bunch of unused images lying around and a less-than ideal performance.This takes care of these issues without me having to worry about it.
## Dependencies
- `go`
- [`cwebp`](https://developers.google.com/speed/webp/docs/cwebp)
- [`gif2webp`](https://developers.google.com/speed/webp/docs/gif2webp) (if GIFs need to be handled)## Install
Either download the [latest binary](https://github.com/EricDriussi/hugo-image-optimizer/releases) and add it to your `$PATH` or install it directly using `go`:
```sh
go install github.com/EricDriussi/hugo-image-optimizer@latest
```Give the binary a nicer name:
```sh
GOBIN=$(go env GOBIN); BASE_PATH=${GOBIN:-$(go env GOPATH)/bin}; mv ${BASE_PATH}/hugo-image-optimizer ${BASE_PATH}/optimize
```## Config
A `optimizer.ini` config file is expected and should look like this:
```ini
[dirs]
posts = content/posts/
images = static/images/
images_exclude = whoami donation[compression]
quality = 50
```This tells the optimizer where your posts and images are located (can be in subdirectories), what subdirectories to ignore when optimizing images, and how much compression to apply (0-100, 100 for max compression).
Add one to your website repo or in `~/.config/`. Specify a different path with `--config`.
If no config file is provided, it will default to the values above.
## Run
Either run it from your website directory or use the `--website-path` flag to specify the desired path.
Run `optimize --help` to check out the available commands and flags.
You can run them all at once with `optimize` or separately with `optimize [CMD]` for more fine-grained control.