Convert Figma logo to code with AI

google logoguetzli

Perceptual JPEG encoder

12,898
977
12,898
122

Top Related Projects

5,428

Improved JPEG encoder.

GUI image optimizer for Mac

Utilities for archiving JPEGs for long term storage.

1,611

Free Lossless Audio Codec

1,989

Mirror only. Please do not send pull requests. See https://chromium.googlesource.com/webm/libwebp/+/HEAD/CONTRIBUTING.md.

Quick Overview

Guetzli is an open-source JPEG encoder developed by Google. It aims to produce significantly smaller JPEG files while maintaining visual quality comparable to other encoders. Guetzli uses a psychovisual model to optimize JPEG encoding for human perception.

Pros

  • Produces smaller JPEG files (20-30% smaller) compared to libjpeg
  • Maintains high visual quality, often indistinguishable from the original
  • Compatible with existing JPEG decoders and browsers
  • Suitable for both web and local image storage optimization

Cons

  • Significantly slower encoding process compared to other JPEG encoders
  • High memory usage during encoding
  • Limited to 8-bit RGB input images
  • No support for progressive JPEG output

Getting Started

To use Guetzli, follow these steps:

  1. Clone the repository:

    git clone https://github.com/google/guetzli.git
    
  2. Build the project:

    cd guetzli
    make
    
  3. Run Guetzli on an image:

    ./bin/Release/guetzli [--quality <int>] [--verbose] <input> <output>
    

    Example:

    ./bin/Release/guetzli --quality 90 input.png output.jpg
    

Note: The --quality parameter controls the trade-off between visual quality and file size (values range from 84 to 110, with 100 being the default).

Competitor Comparisons

5,428

Improved JPEG encoder.

Pros of mozjpeg

  • Faster encoding speed than Guetzli
  • Supports both lossy and lossless JPEG compression
  • More actively maintained with regular updates

Cons of mozjpeg

  • Generally produces larger file sizes compared to Guetzli
  • Less effective at preserving perceptual quality at very low bitrates

Code Comparison

Guetzli (C++):

std::string CompressJpegXl(const std::vector<uint8_t>& rgb,
                           int xsize, int ysize,
                           float butteraugli_target,
                           ThreadPool* pool) {
  // Compression logic here
}

mozjpeg (C):

GLOBAL(int)
jpeg_write_scanlines(j_compress_ptr cinfo, JSAMPARRAY scanlines,
                     JDIMENSION num_lines) {
  // Compression logic here
}

Both projects aim to improve JPEG compression, but they take different approaches. Guetzli focuses on perceptual optimization and achieving smaller file sizes at the cost of slower encoding, while mozjpeg offers a balance between compression efficiency and encoding speed. Guetzli is written in C++ and uses more modern techniques, whereas mozjpeg is written in C and builds upon the existing libjpeg library. The choice between the two depends on specific use cases and priorities regarding file size, encoding speed, and image quality.

GUI image optimizer for Mac

Pros of ImageOptim

  • Supports multiple image formats (PNG, JPEG, GIF, etc.)
  • Offers a user-friendly GUI for easy image optimization
  • Continuously updated with new features and improvements

Cons of ImageOptim

  • May not achieve the same level of compression as Guetzli for JPEG images
  • Lacks fine-grained control over compression parameters
  • Primarily designed for macOS, limiting cross-platform usage

Code Comparison

While both projects focus on image optimization, their implementation and usage differ significantly. Guetzli is primarily used as a command-line tool or library, while ImageOptim offers a GUI application. Here's a basic usage example for each:

Guetzli:

#include "guetzli/processor.h"
std::string in_data = ReadFileOrDie(argv[1]);
std::string out_data;
guetzli::Params params;
ProcessJpegData(params, in_data, &out_data);

ImageOptim:

import ImageOptim

let optimizer = ImageOptimizer()
optimizer.optimize(image: inputImage) { result in
    switch result {
    case .success(let optimizedImage):
        // Use optimized image
    case .failure(let error):
        // Handle error
    }
}

Note that ImageOptim's code is typically used within a macOS application context, while Guetzli's code is more focused on low-level image processing.

Utilities for archiving JPEGs for long term storage.

Pros of jpeg-archive

  • Faster processing times for image compression
  • Includes additional tools for image comparison and optimization
  • Supports batch processing of multiple images

Cons of jpeg-archive

  • Generally produces larger file sizes compared to Guetzli
  • May result in lower image quality in some cases
  • Less actively maintained (last update was in 2021)

Code Comparison

jpeg-archive:

int compress_jpeg(const char *input, const char *output, int quality, int strip, int progressive) {
    struct jpeg_compress_struct cinfo;
    struct jpeg_error_mgr jerr;
    FILE *infile, *outfile;
    JSAMPARRAY buffer;
    int row_stride;

Guetzli:

bool ProcessJpegData(const JPEGData& jpg_in, const int quality,
                     JPEGData* jpg_out, bool save_jpeg_header) {
  std::vector<uint8_t> rgb_output;
  if (!DecodeJpegToRGB(jpg_in, &rgb_output)) {
    return false;
  }

Both projects focus on JPEG compression, but their approaches and implementations differ. jpeg-archive provides a broader set of tools for image optimization, while Guetzli focuses on high-quality compression at the cost of slower processing times.

1,611

Free Lossless Audio Codec

Pros of FLAC

  • Lossless audio compression, preserving original audio quality
  • Widely supported across many devices and platforms
  • Open-source and royalty-free format

Cons of FLAC

  • Larger file sizes compared to lossy formats
  • Not as efficient for image compression (primarily audio-focused)

Code Comparison

FLAC (audio encoding):

FLAC__StreamEncoder *encoder = FLAC__stream_encoder_new();
FLAC__stream_encoder_set_verify(encoder, true);
FLAC__stream_encoder_set_compression_level(encoder, 5);
FLAC__stream_encoder_init_file(encoder, output_filename, NULL, NULL);
FLAC__stream_encoder_process_interleaved(encoder, buffer, samples);

Guetzli (image encoding):

guetzli::ProcessStats stats;
std::string output;
guetzli::Params params;
params.quality = 95;
guetzli::Process(params, &stats, input_rgb, width, height, &output);

FLAC is primarily designed for lossless audio compression, while Guetzli focuses on lossy JPEG image compression. FLAC offers perfect audio reproduction and wide compatibility, but results in larger file sizes. Guetzli aims to produce smaller JPEG files while maintaining visual quality, but is limited to image processing. The code snippets demonstrate their different focuses, with FLAC handling audio streams and Guetzli processing image data.

1,989

Mirror only. Please do not send pull requests. See https://chromium.googlesource.com/webm/libwebp/+/HEAD/CONTRIBUTING.md.

Pros of libwebp

  • Supports both lossy and lossless compression
  • Offers animation capabilities (WebP format)
  • Faster encoding and decoding compared to Guetzli

Cons of libwebp

  • Generally produces larger file sizes than Guetzli for similar quality
  • Less effective at preserving fine details in high-quality images

Code Comparison

libwebp

WebPConfig config;
WebPConfigInit(&config);
config.quality = 75;
WebPEncode(&config, &picture);

Guetzli

std::string compressed;
guetzli::Process(params, &processor, input_image, &compressed);

Key Differences

  • Guetzli focuses solely on JPEG compression, while libwebp implements the WebP format
  • Guetzli aims for higher quality at smaller file sizes, but with slower encoding
  • libwebp offers more versatility with animation support and both lossy/lossless options

Use Cases

  • Guetzli: High-quality image compression for web content, especially when file size is critical
  • libwebp: General-purpose image compression, particularly suitable for websites needing animation support or faster encoding/decoding

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Guetzli

Introduction

Guetzli is a JPEG encoder that aims for excellent compression density at high visual quality. Guetzli-generated images are typically 20-30% smaller than images of equivalent quality generated by libjpeg. Guetzli generates only sequential (nonprogressive) JPEGs due to faster decompression speeds they offer.

Build Status

Building

On POSIX systems

  1. Get a copy of the source code, either by cloning this repository, or by downloading an archive and unpacking it.
  2. Install libpng. If using your operating system package manager, install development versions of the packages if the distinction exists.
    • On Ubuntu, do apt-get install libpng-dev.
    • On Fedora, do dnf install libpng-devel.
    • On Arch Linux, do pacman -S libpng.
    • On Alpine Linux, do apk add libpng-dev.
  3. Run make and expect the binary to be created in bin/Release/guetzli.

On Windows

  1. Get a copy of the source code, either by cloning this repository, or by downloading an archive and unpacking it.
  2. Install Visual Studio 2015 and vcpkg
  3. Install libpng using vcpkg: .\vcpkg install libpng.
  4. Cause the installed packages to be available system-wide: .\vcpkg integrate install. If you prefer not to do this, refer to vcpkg's documentation.
  5. Open the Visual Studio project enclosed in the repository and build it.

On macOS

To install using Homebrew:

  1. Install Homebrew
  2. brew install guetzli

To install using the repository:

  1. Get a copy of the source code, either by cloning this repository, or by downloading an archive and unpacking it.
  2. Install Homebrew or MacPorts
  3. Install libpng
    • Using Homebrew: brew install libpng.
    • Using MacPorts: port install libpng (You may need to use sudo).
  4. Run the following command to build the binary in bin/Release/guetzli.
    • If you installed using Homebrew simply use make
    • If you installed using MacPorts use CFLAGS='-I/opt/local/include' LDFLAGS='-L/opt/local/lib' make

With Bazel

There's also a Bazel build configuration provided. If you have Bazel installed, you can also compile Guetzli by running bazel build -c opt //:guetzli.

Using

Note: Guetzli uses a large amount of memory. You should provide 300MB of memory per 1MPix of the input image.

Note: Guetzli uses a significant amount of CPU time. You should count on using about 1 minute of CPU per 1 MPix of input image.

Note: Guetzli assumes that input is in sRGB profile with a gamma of 2.2. Guetzli will ignore any color-profile metadata in the image.

To try out Guetzli you need to build or download the Guetzli binary. The binary reads a PNG or JPEG image and creates an optimized JPEG image:

guetzli [--quality Q] [--verbose] original.png output.jpg
guetzli [--quality Q] [--verbose] original.jpg output.jpg

Note that Guetzli is designed to work on high quality images. You should always prefer providing uncompressed input images (e.g. that haven't been already compressed with any JPEG encoders, including Guetzli). While it will work on other images too, results will be poorer. You can try compressing an enclosed sample high quality image.

You can pass a --quality Q parameter to set quality in units equivalent to libjpeg quality. You can also pass a --verbose flag to see a trace of encoding attempts made.

Please note that JPEG images do not support alpha channel (transparency). If the input is a PNG with an alpha channel, it will be overlaid on black background before encoding.