Introduction | image-optimizer-go | Spatie       

 SPATIE  

image-optimizer-go
==================

spatie.be/open-source

  [Docs](https://spatie.be/index.php/docs)  [Image-optimizer-go](https://spatie.be/index.php/docs/image-optimizer-go/v1)  Introduction

 Version   v1      

 Other versions for crawler [v1](https://spatie.be/docs/image-optimizer-go/v1) 

  Introduction    
- [ Introduction ](https://spatie.be/index.php/docs/image-optimizer-go/v1/introduction)
- [ Installation and setup ](https://spatie.be/index.php/docs/image-optimizer-go/v1/installation-and-setup)
- [ Usage ](https://spatie.be/index.php/docs/image-optimizer-go/v1/usage)
- [ Which tools will do what? ](https://spatie.be/index.php/docs/image-optimizer-go/v1/which-tools-will-do-what)
- [ Logging the optimization process ](https://spatie.be/index.php/docs/image-optimizer-go/v1/logging-the-optimization-process)
- [ Example conversions ](https://spatie.be/index.php/docs/image-optimizer-go/v1/example-conversions)
- [ Testing ](https://spatie.be/index.php/docs/image-optimizer-go/v1/testing)
- [ Releasing ](https://spatie.be/index.php/docs/image-optimizer-go/v1/releasing)
- [ Changelog ](https://spatie.be/index.php/docs/image-optimizer-go/v1/changelog)
- [ Support us ](https://spatie.be/index.php/docs/image-optimizer-go/v1/support-us)

  Image-optimizer-go 
====================

 Easily optimize images using Go 

### Useful links

- [Repository](https://github.com/spatie/image-optimizer-go)
- [Discussions](https://github.com/spatie/image-optimizer-go/discussions)

Introduction
------------

This package can optimize PNGs, JPGs, WEBPs, AVIFs, SVGs and GIFs by running them through a chain of various [image optimization tools](installation-and-setup#optimization-tools). Here's how you can use it:

```
chain := imageoptimizer.New()
err := chain.Optimize(ctx, "image.jpg")
```

The image will be overwritten by an optimized version which should be smaller. The package chooses tools by file contents. Missing binaries are treated like other optimizer failures. By default they are logged and the chain continues.

Here are some [example conversions](example-conversions) that have been done by this package.

Import `github.com/spatie/image-optimizer-go` as `imageoptimizer`. The examples use a `context.Context` named `ctx`. Always handle returned errors in your application.

This is the Go port of [spatie/image-optimizer](https://github.com/spatie/image-optimizer). It has no Go module dependencies and does not require PHP or Laravel.

Start with [installation and setup](installation-and-setup), then read [usage](usage).

 A good
match?
-------------

### What we do best

- All things Laravel
- Custom frontend components
- Building APIs
- AI-powered features
- Simplifying things
- Clean solutions
- Integrating services

### Not our cup of tea

- WordPress themes
- Cutting corners
- Free mockups to win a job
- "Just execute the briefing"

 In short: we'd like to be a **substantial part** of your project.

 [ Get in touch via email ](mailto:info@spatie.be?subject=A%20good%20match%21&body=Tell%20us%20as%20much%20as%20you%20can%20about%0A-%20your%20online%20project%0A-%20your%20planning%0A-%20your%20budget%0A-%20%E2%80%A6%0A%0AAnything%20that%20helps%20us%20to%20start%20straightforward%21)
