Convert Figma logo to code with AI

danielgtaylor logojpeg-archive

Utilities for archiving JPEGs for long term storage.

1,161
121
1,161
47

Top Related Projects

5,428

Improved JPEG encoder.

12,898

Perceptual JPEG encoder

Main libjpeg-turbo repository

🧙‍♂️ ImageMagick 7

Lossy PNG compressor — pngquant command based on libimagequant library

GUI image optimizer for Mac

Quick Overview

JPEG-Archive is a command-line utility designed to efficiently compress JPEG images while maintaining visual quality. It uses advanced compression techniques and quality assessment algorithms to achieve smaller file sizes without significant perceptible loss in image quality.

Pros

  • Achieves high compression ratios while preserving visual quality
  • Supports various compression methods and quality assessment algorithms
  • Includes a handy comparison tool for before/after analysis
  • Open-source and actively maintained

Cons

  • Command-line interface may be intimidating for non-technical users
  • Limited to JPEG format only
  • Compression process can be time-consuming for large batches of images
  • Requires some experimentation to find optimal settings for specific use cases

Getting Started

To get started with JPEG-Archive, follow these steps:

  1. Clone the repository:

    git clone https://github.com/danielgtaylor/jpeg-archive.git
    
  2. Build the project:

    cd jpeg-archive
    make
    
  3. Compress a JPEG image:

    ./jpeg-recompress input.jpg output.jpg
    
  4. For more options and advanced usage, refer to the project's README and documentation.

Competitor Comparisons

5,428

Improved JPEG encoder.

Pros of mozjpeg

  • More actively maintained with frequent updates and contributions
  • Offers a wider range of optimization techniques and algorithms
  • Provides better compression ratios while maintaining high image quality

Cons of mozjpeg

  • More complex to use and integrate, requiring more technical expertise
  • Slower encoding speed compared to jpeg-archive
  • Larger codebase and dependencies, potentially increasing build times

Code Comparison

mozjpeg:

int main(int argc, char **argv) {
  struct jpeg_compress_struct cinfo;
  struct jpeg_error_mgr jerr;
  cinfo.err = jpeg_std_error(&jerr);
  jpeg_create_compress(&cinfo);
}

jpeg-archive:

int main(int argc, char *argv[]) {
    if (argc < 3) {
        printf("Usage: %s input.jpg output.jpg\n", argv[0]);
        return 1;
    }
    compress_jpeg(argv[1], argv[2]);
}

Summary

mozjpeg offers more advanced optimization techniques and better compression ratios, making it suitable for projects requiring high-quality image compression. However, it comes with increased complexity and slower encoding speed. jpeg-archive, on the other hand, provides a simpler interface and faster encoding, but with fewer optimization options. The choice between the two depends on the specific requirements of the project, balancing compression quality, speed, and ease of use.

12,898

Perceptual JPEG encoder

Pros of Guetzli

  • Achieves higher compression ratios while maintaining perceptual quality
  • Utilizes psychovisual modeling for optimized image compression
  • Developed and maintained by Google, potentially offering better long-term support

Cons of Guetzli

  • Significantly slower compression process compared to JPEG-Archive
  • Higher memory usage during compression
  • Limited to JPEG output format only

Code Comparison

Guetzli (C++):

guetzli::Params params;
params.butteraugli_target = 0.5;
guetzli::ProcessJpegData(params, jpg_data, jpg_data_len, &output_data);

JPEG-Archive (C):

mozjpeg_compress(input_file, output_file, quality, progressive);

JPEG-Archive offers a simpler API for compression, while Guetzli provides more fine-tuned control over the compression process.

Summary

Guetzli excels in achieving higher compression ratios with maintained perceptual quality, leveraging advanced psychovisual modeling. However, it comes at the cost of slower processing times and higher resource usage. JPEG-Archive, on the other hand, offers faster compression and supports multiple output formats, making it more versatile for general use cases. The choice between the two depends on specific project requirements, balancing compression quality against processing speed and resource constraints.

Main libjpeg-turbo repository

Pros of libjpeg-turbo

  • Highly optimized JPEG codec with SIMD acceleration
  • Widely used and well-maintained library
  • Supports both compression and decompression

Cons of libjpeg-turbo

  • Focuses solely on JPEG format
  • May require more complex integration for specific use cases

Code Comparison

libjpeg-turbo:

#include <turbojpeg.h>

tjhandle tjInstance = tjInitCompress();
tjCompress2(tjInstance, sourceBuffer, width, pitch, height,
            pixelFormat, &jpegBuf, &jpegSize, jpegSubsamp,
            jpegQual, flags);
tjDestroy(tjInstance);

jpeg-archive:

#include "mozjpeg/jpeglib.h"

jpeg_create_compress(&cinfo);
jpeg_stdio_dest(&cinfo, outfile);
jpeg_set_defaults(&cinfo);
jpeg_set_quality(&cinfo, quality, TRUE);
jpeg_start_compress(&cinfo, TRUE);

Summary

libjpeg-turbo is a high-performance JPEG codec library with broad support and optimization. It's ideal for applications requiring fast JPEG processing. jpeg-archive, on the other hand, is a collection of utilities for archiving JPEGs, utilizing MozJPEG for compression. It offers a more specialized toolset for JPEG archiving and optimization tasks. The choice between them depends on whether you need a general-purpose JPEG library or specific archiving tools.

🧙‍♂️ ImageMagick 7

Pros of ImageMagick

  • Comprehensive suite of image processing tools and capabilities
  • Supports a wide range of image formats beyond JPEG
  • Extensive documentation and large community support

Cons of ImageMagick

  • Larger footprint and more complex installation process
  • May be overkill for simple JPEG optimization tasks
  • Can be slower for batch processing of JPEG images

Code Comparison

ImageMagick (command-line example):

convert input.jpg -quality 85 -strip output.jpg

jpeg-archive (command-line example):

jpeg-recompress --quality high --min 60 input.jpg output.jpg

Key Differences

  • jpeg-archive is specifically designed for JPEG optimization, while ImageMagick is a more general-purpose image processing tool.
  • jpeg-archive uses more advanced compression techniques tailored for JPEG images, potentially resulting in better quality-to-size ratios.
  • ImageMagick offers a wider range of image manipulation options beyond compression.

Use Cases

  • Choose jpeg-archive for focused JPEG optimization tasks, especially when dealing with large batches of images.
  • Opt for ImageMagick when you need a versatile tool for various image processing tasks across multiple formats.

Performance

  • jpeg-archive generally offers faster processing times for JPEG optimization.
  • ImageMagick may be slower for batch JPEG processing but provides more flexibility for complex image manipulations.

Lossy PNG compressor — pngquant command based on libimagequant library

Pros of pngquant

  • Specializes in PNG optimization, offering excellent compression for PNG files
  • Supports alpha channel preservation, crucial for transparent images
  • Widely used and actively maintained, with frequent updates and improvements

Cons of pngquant

  • Limited to PNG format, while jpeg-archive supports JPEG optimization
  • May not achieve the same level of compression as jpeg-archive for photographic images
  • Requires more processing time compared to jpeg-archive for large batches of images

Code Comparison

pngquant:

void filter_image(png24_image *img, png_pixel *row, int width, int y, int depth)
{
    for(int x=0; x < width; x++) {
        row[x] = get_pixel(img, x, y);
    }
}

jpeg-archive:

static void encode_mcu_DC_first(j_compress_ptr cinfo, JBLOCKROW *MCU_data)
{
    int blkn, ci, tbl;
    JBLOCKROW block;
    jpeg_component_info *compptr;
}

Both projects focus on image optimization but target different file formats. pngquant is specifically designed for PNG compression, while jpeg-archive specializes in JPEG optimization. The code snippets demonstrate their respective approaches to handling image data, with pngquant focusing on pixel manipulation and jpeg-archive dealing with JPEG-specific encoding processes.

GUI image optimizer for Mac

Pros of ImageOptim

  • User-friendly GUI application for macOS, making it accessible to non-technical users
  • Supports multiple image formats (JPEG, PNG, GIF) and various optimization algorithms
  • Actively maintained with regular updates and improvements

Cons of ImageOptim

  • Limited to macOS platform, reducing accessibility for Windows and Linux users
  • Less control over specific compression parameters compared to command-line tools
  • May not achieve the same level of compression as specialized JPEG-only tools

Code Comparison

While a direct code comparison is not particularly relevant due to the different nature of these projects (GUI application vs. command-line tool), we can compare their usage:

ImageOptim (drag-and-drop or CLI):

open -a ImageOptim image.jpg

jpeg-archive (CLI):

jpeg-recompress --quality high --min 60 input.jpg output.jpg

Summary

ImageOptim offers a user-friendly GUI for various image formats on macOS, while jpeg-archive provides a specialized command-line tool for JPEG compression with more granular control. The choice between them depends on the user's platform, technical expertise, and specific compression needs.

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

JPEG Archive Build Status Build status Version License

Utilities for archiving photos for saving to long term storage or serving over the web. The goals are:

  • Use a common, well supported format (JPEG)
  • Minimize storage space and cost
  • Identify duplicates / similar photos

Approach:

  • Command line utilities and scripts
  • Simple options and useful help
  • Good quality output via sane defaults

Contributions to this project are very welcome.

Download

You can download the latest source and binary releases from the JPEG Archive releases page. Windows binaries for the latest commit are available from the Windows CI build server.

If you are looking for an easy way to run these utilities in parallel over many files to utilize all CPU cores, please also download Ladon or GNU Parallel. You can then use the jpeg-archive command below or use ladon directly. Example:

# Re-compress JPEGs and replace the originals
ladon "Photos/**/*.jpg" -- jpeg-recompress FULLPATH FULLPATH

# Re-compress JPEGs into the new directory 'Comp'
ladon -m Comp/RELDIR "Photos/**/*.jpg" -- jpeg-recompress FULLPATH Comp/RELPATH

Utilities

The following utilities are part of this project. All of them accept a --help parameter to see the available options.

jpeg-archive

Compress RAW and JPEG files in a folder utilizing all CPU cores. This is a simple shell script that uses the utilities below. It requires:

# Compress a folder of images
cd path/to/photos
jpeg-archive

# Custom quality and metric
jpeg-archive --quality medium --method smallfry

jpeg-recompress

Compress JPEGs by re-encoding to the smallest JPEG quality while keeping perceived visual quality the same and by making sure huffman tables are optimized. This is a lossy operation, but the images are visually identical and it usually saves 30-70% of the size for JPEGs coming from a digital camera, particularly DSLRs. By default all EXIF/IPTC/XMP and color profile metadata is copied over, but this can be disabled to save more space if desired.

There is no need for the input file to be a JPEG. In fact, you can use jpeg-recompress as a replacement for cjpeg by using PPM input and the --ppm option.

The better the quality of the input image is, the better the output will be.

Some basic photo-related editing options are available, such as removing fisheye lens distortion.

Demo

Below are two 100% crops of Nikon's D3x Sample Image 2. The left shows the original image from the camera, while the others show the output of jpeg-recompress with the medium quality setting and various comparison methods. By default SSIM is used, which lowers the file size by 88%. The recompression algorithm chooses a JPEG quality of 80. By comparison the veryhigh quality setting chooses a JPEG quality of 93 and saves 70% of the file size.

JPEG recompression comparison

Why are they different sizes? The default quality settings are set to average out to similar visual quality over large data sets. They may differ on individual photos (like above) because each metric considers different parts of the image to be more or less important for compression.

Image Comparison Metrics

The following metrics are available when using jpeg-recompress. SSIM is the default.

NameOptionDescription
MPE-m mpeMean pixel error (as used by imgmin)
SSIM-m ssimStructural similarity DEFAULT
MS-SSIM*-m ms-ssimMulti-scale structural similarity (slow!) (2008 paper)
SmallFry-m smallfryLinear-weighted BBCQ-like (original project, 2011 BBCQ paper)

Note: The SmallFry algorithm may be patented so use with caution.

Subsampling

The JPEG format allows for subsampling of the color channels to save space. For each 2x2 block of pixels per color channel (four pixels total) it can store four pixels (all of them), two pixels or a single pixel. By default, the JPEG encoder subsamples the non-luma channels to two pixels (often referred to as 4:2:0 subsampling). Most digital cameras do the same because of limitations in the human eye. This may lead to unintended behavior for specific use cases (see #12 for an example), so you can use --subsample disable to disable this subsampling.

Example Commands

# Default settings
jpeg-recompress image.jpg compressed.jpg

# High quality example settings
jpeg-recompress --quality high --min 60 image.jpg compressed.jpg

# Slow high quality settings (3-4x slower than above, slightly more accurate)
jpeg-recompress --accurate --quality high --min 60 image.jpg compressed.jpg

# Use SmallFry instead of SSIM
jpeg-recompress --method smallfry image.jpg compressed.jpg

# Use 4:4:4 sampling (disables subsampling).
jpeg-recompress --subsample disable image.jpg compressed.jpg

# Remove fisheye distortion (Tokina 10-17mm on APS-C @ 10mm)
jpeg-recompress --defish 2.6 --zoom 1.2 image.jpg defished.jpg

# Read from stdin and write to stdout with '-' as the filename
jpeg-recompress - - <image.jpg >compressed.jpg

# Convert RAW to JPEG via PPM from stdin
dcraw -w -q 3 -c IMG_1234.CR2 | jpeg-recompress --ppm - compressed.jpg

# Disable progressive mode (not recommended)
jpeg-recompress --no-progressive image.jpg compressed.jpg

# Disable all output except for errors
jpeg-recompress --quiet image.jpg compressed.jpg

jpeg-compare

Compare two JPEG photos to judge how similar they are. The fast comparison method returns an integer from 0 to 99, where 0 is identical. PSNR, SSIM, and MS-SSIM return floats but require images to be the same dimensions.

# Do a fast compare of two images
jpeg-compare image1.jpg image2.jpg

# Calculate PSNR
jpeg-compare --method psnr image1.jpg image2.jpg

# Calculate SSIM
jpeg-compare --method ssim image1.jpg image2.jpg

jpeg-hash

Create a hash of an image that can be used to compare it to other images quickly.

jpeg-hash image.jpg

Building

Dependencies

Ubuntu

Ubuntu users can install via apt-get:

sudo apt-get install build-essential autoconf pkg-config nasm libtool
git clone https://github.com/mozilla/mozjpeg.git
cd mozjpeg
autoreconf -fiv
./configure --with-jpeg8
make
sudo make install

Mac OS X

Mac users can install it via Homebrew:

brew install mozjpeg

FreeBSD

pkg install mozjpeg
git clone https://github.com/danielgtaylor/jpeg-archive.git
cd jpeg-archive/
gmake
sudo gmake install

Windows

The Makefile should work with MinGW/Cygwin/etc and standard GCC. Patches welcome.

To get everything you need to build, install these:

Run Github for windows. In the settings, set Git Bash as the shell. Open Git Shell from the start menu.

# Update PATH to include MinGW/NASM bin folder, location on your system may vary
export PATH=/c/mingw/mingw32/bin:/c/Program\ Files \(x68\)/nasm:$PATH

# Build mozjpeg or download https://www.dropbox.com/s/98jppfgds2xjblu/libjpeg.a
git clone https://github.com/mozilla/mozjpeg.git
cd mozjpeg
cmake -G "MSYS Makefiles" -D CMAKE_C_COMPILER=gcc.exe -D CMAKE_MAKE_PROGRAM=mingw32-make.exe  -D WITH_JPEG8=1
mingw32-make
cd ..

# Build jpeg-archive
git clone https://github.com/danielgtaylor/jpeg-archive
cd jpeg-archive
CC=gcc mingw32-make

JPEG-Archive should now be built.

Compiling (Linux and Mac OS X)

The Makefile should work as-is on Ubuntu and Mac OS X. Other platforms may need to set the location of libjpeg.a or make other tweaks.

make

Installation

Install the binaries into /usr/local/bin:

sudo make install

Links / Alternatives

License

All are released under an MIT license.

http://dgt.mit-license.org/