Introduction | image-optimizer-rust | Spatie       

 SPATIE  

image-optimizer-rust
====================

spatie.be/open-source

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

 Version   v1      

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

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

  Image-optimizer-rust 
======================

 Optimize images with native command-line tools from Rust 

### Useful links

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

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

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

```
use spatie_image_optimizer::OptimizerChainFactory;

let optimizer_chain = OptimizerChainFactory::create();
optimizer_chain.optimize("photo.jpg")?;
# Ok::(())
```

The image at `photo.jpg` will be overwritten by an optimized version. The package automatically decides which tools to use for the image's format. Install the [binaries you need](installation-and-setup#optimization-tools) first. By default, failures, including missing binaries, are logged and the chain continues.

To keep the original image, use `optimize_to("photo.jpg", "optimized.jpg")`. If you only want to replace a file when optimization succeeds and makes it smaller, enable [safe output](usage#keeping-the-original-safe).

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

 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)
