MozJpegSharp 2.1.12

There is a newer version of this package available.
See the version list below for details.
dotnet add package MozJpegSharp --version 2.1.12                
NuGet\Install-Package MozJpegSharp -Version 2.1.12                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="MozJpegSharp" Version="2.1.12" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add MozJpegSharp --version 2.1.12                
#r "nuget: MozJpegSharp, 2.1.12"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install MozJpegSharp as a Cake Addin
#addin nuget:?package=MozJpegSharp&version=2.1.12

// Install MozJpegSharp as a Cake Tool
#tool nuget:?package=MozJpegSharp&version=2.1.12                

MozJpegSharp (.NET wrapper for MozJPEG)

NuGet version (MozJpegSharp) Build Status

MozJPEG reduces file sizes of JPEG images while retaining quality and compatibility with the vast majority of the world's deployed decoders.

This library provides .NET wrappers for MozJPEG, allowing you to use it from any .NET language, such as C#.

We also provide precompiled binaries of MozJPEG for Windows (x86/x64), Linux x64 and macOS. On these platforms you just need to install the package MozJpegSharp to start producing smaller JPEGs.

Release Notes v2.1.12 (from 1.0.27)

  • Update MozJPEG to version 2021-07-21
  • Add support for SkiaSharp
  • Split GDI+ support in second package
  • Add support for OS-installed mozjpeg(/libturbojpeg)
  • Restructure packages for better cross platform experience
  • Improve build process

Upgrading from v1:

  • if you used methods with System.Drawing.Bitmap in their signature, please also install the MozJpegSharp.GdiPlus package, in addition to MozJpegSharp

Package Overview

This project provides multiple NuGet packages:

Package Description
MozJpegSharp Convenience package. Provides easy installation for MozJpegSharp.Core and MozJpegSharp.NativeAssets. All you need to recompress existing .jpg files on all supported platforms.
MozJpegSharp.Core Just the managed wrapper. Useful if you compile MozJPEG from source or get it from you OS package manager.
MozJpegSharp.NativeAssets Just the compiled native assets. Hardly useful solely installed.
MozJpegSharp.SkiaSharp Install besides MozJpegSharp. Extension methods for working with SKBitmap. Useful for compressing images in applications that already use SkiaSharp. Also great performance and cross platform compatibility. Good choice for new cross-platform projects that need to support more cases then just recompressing JPEGs.
MozJpegSharp.GdiPlus Install besides MozJpegSharp. Extension methods for working with System.Drawing.Bitmap objects. Useful for compressing any kind of image on Windows/.Net Framework.

Usage

Recompression using just MozJpegSharp:

var inFile = "in.jpg";
var outFile = "out.jpg";
var inBytes = await File.ReadAllBytesAsync(inFile);
var compressed = MozJpeg.Recompress(inBytes.AsSpan(), quality: 80);
await File.WriteAllBytesAsync(outFile, compressed);

Example usage for MozJpegSharp.GdiPlus:

var inFile = "in.jpg"; // does not need to be jpg
var outFile = "out.jpg";
using var bmp = new Bitmap(file);
using var tjc = new MozJpegSharp.TJCompressor();
var compressed = tjc.Compress(bmp, MozJpegSharp.TJSubsamplingOption.Chrominance420, 75, MozJpegSharp.TJFlags.None);
File.WriteAllBytes(outFile, compressed);
There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on MozJpegSharp:

Repository Stars
n00mkrad/cupscale
Image Upscaling GUI based on ESRGAN
Version Downloads Last updated
3.0.8 8,611 1/6/2023
3.0.2 314 1/4/2023 3.0.2 is deprecated because it has critical bugs.
2.1.12 6,892 8/10/2021
1.0.27 10,747 3/12/2020
0.2.1-ge37ca80287 395 2/18/2020