Example conversions | 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)  Example conversions

 Version   v1      

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

  Example conversions    
- [ 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)

 Example conversions
===================

###  On this page 

1. [ jpg ](#content-jpg)
2. [ webp ](#content-webp)
3. [ avif ](#content-avif)
4. [ png ](#content-png)
5. [ svg ](#content-svg)
6. [ gif ](#content-gif)
7. [ Trying it yourself ](#content-trying-it-yourself)

Here are some real-life example conversions done by this package.

The JPG, WebP, AVIF, PNG and SVG sources are the same images used by [spatie/image-optimizer](https://github.com/spatie/image-optimizer#example-conversions), optimized with the Rust package's default chain. The photo by [Jeff Sheldon](https://unsplash.com/photos/jTeQavJjBDs) was resized to 2048 pixels wide for the original PHP examples. We used those existing fixtures without resizing them again. The GIF is an additional test fixture in this Rust package.

FormatOriginal bytesOptimized bytesReductionJPG789,989523,42233.74%WebP472,102414,03612.30%AVIF742,683197,71273.38%PNG40,3029,76475.77%SVG25,58619,16425.10%GIF652,193609,9776.47%Sizes are measured in bytes, not rounded kilobytes. These results were measured on Linux on November 23, 2026, with jpegoptim 1.4.7, pngquant 2.18.0, OptiPNG 0.7.8, SVGO 3.3.5, Gifsicle 1.96, cwebp 1.5.0 and libavif 1.2.1 with the AOM 3.12.1 encoder. Results will vary with tool versions and image content. A smaller file does not imply identical pixels; JPEG, PNG, WebP and AVIF optimization can be lossy. No DSSIM score was measured.

jpg
-----------------------------------------------------------------

Original, 789,989 bytes:

![Original JPG photo](https://fls-a2e2b4d6-b344-41b9-abd1-6c06196a36b3.laravel.cloud/docs/image-optimizer-rust/v1/examples/original-image.jpg)

Optimized, 523,422 bytes (33.74% smaller):

![Optimized JPG photo](https://fls-a2e2b4d6-b344-41b9-abd1-6c06196a36b3.laravel.cloud/docs/image-optimizer-rust/v1/examples/image.jpg)

webp
--------------------------------------------------------------------

Original, 472,102 bytes:

![Original WebP photo](https://fls-a2e2b4d6-b344-41b9-abd1-6c06196a36b3.laravel.cloud/docs/image-optimizer-rust/v1/examples/original-image.webp)

Optimized, 414,036 bytes (12.30% smaller):

![Optimized WebP photo](https://fls-a2e2b4d6-b344-41b9-abd1-6c06196a36b3.laravel.cloud/docs/image-optimizer-rust/v1/examples/image.webp)

avif
--------------------------------------------------------------------

Original, 742,683 bytes:

![Original AVIF photo](https://fls-a2e2b4d6-b344-41b9-abd1-6c06196a36b3.laravel.cloud/docs/image-optimizer-rust/v1/examples/original-image.avif)

Optimized, 197,712 bytes (73.38% smaller):

![Optimized AVIF photo](https://fls-a2e2b4d6-b344-41b9-abd1-6c06196a36b3.laravel.cloud/docs/image-optimizer-rust/v1/examples/image.avif)

Photo credit: Jeff Sheldon, via [Unsplash](https://unsplash.com).

png
-----------------------------------------------------------------

Original, Photoshop "Save for web" export with transparency, 40,302 bytes:

![Original PNG logo](https://fls-a2e2b4d6-b344-41b9-abd1-6c06196a36b3.laravel.cloud/docs/image-optimizer-rust/v1/examples/original-logo.png)

Optimized, 9,764 bytes (75.77% smaller):

![Optimized PNG logo](https://fls-a2e2b4d6-b344-41b9-abd1-6c06196a36b3.laravel.cloud/docs/image-optimizer-rust/v1/examples/logo.png)

svg
-----------------------------------------------------------------

Original, Illustrator web-optimized export, 25,586 bytes:

![Original SVG graph](https://fls-a2e2b4d6-b344-41b9-abd1-6c06196a36b3.laravel.cloud/docs/image-optimizer-rust/v1/examples/original-graph.svg)

Optimized, 19,164 bytes (25.10% smaller):

![Optimized SVG graph](https://fls-a2e2b4d6-b344-41b9-abd1-6c06196a36b3.laravel.cloud/docs/image-optimizer-rust/v1/examples/graph.svg)

gif
-----------------------------------------------------------------

Original, 652,193 bytes:

![Original animated GIF](https://fls-a2e2b4d6-b344-41b9-abd1-6c06196a36b3.laravel.cloud/docs/image-optimizer-rust/v1/examples/original-animated.gif)

Optimized, 609,977 bytes (6.47% smaller):

![Optimized animated GIF](https://fls-a2e2b4d6-b344-41b9-abd1-6c06196a36b3.laravel.cloud/docs/image-optimizer-rust/v1/examples/animated.gif)

Trying it yourself
--------------------------------------------------------------------------------------------------------------

Install the [optimization tools](installation-and-setup#optimization-tools), clone the repository and run this code from its root. It writes the results to `optimized-examples` and leaves the source images untouched:

```
use spatie_image_optimizer::OptimizerChainFactory;
use std::{fs, path::Path};

fs::create_dir_all("optimized-examples")?;
for name in ["image.jpg", "image.webp", "image.avif", "logo.png", "graph.svg", "animated.gif"] {
    let source = Path::new("tests/fixtures").join(name);
    let output = Path::new("optimized-examples").join(name);
    let report = OptimizerChainFactory::create()
        .safe_output(true)
        .throws(true)
        .optimize_to_with_report(&source, &output)?;
    println!("{name}: {} -> {} bytes", report.original_bytes, fs::metadata(output)?.len());
}
# Ok::(())
```

 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)
