Skip to content

Repository files navigation

MIT License CI_CD Nuget

Tinify API client for .NET

.NET client for the Tinify API, used for TinyPNG and TinyJPG. Tinify compresses your images intelligently. Read more at http://tinify.com.

Documentation

Go to the documentation for the .NET client.

Installation

Install the API client:

Install-Package Tinify

Or add this to your project.json:

{
  "dependencies": {
    "Tinify": "*",
  }
}

Usage

using TinifyAPI;

class Compress
{
  static void Main()
  {
    Tinify.Key = "YOUR_API_KEY";
    Tinify.FromFile("unoptimized.png").ToFile("optimized.png").Wait();
  }
}

Convert to another format with the Format constants (WebP, Png, Jpeg, Jpg, Avif, Jxl and Any):

Tinify.FromFile("unoptimized.png")
    .Convert(new { type = Format.Jxl })
    .ToFile("optimized.jxl")
    .Wait();

Pass several and the API returns the smallest result:

var result = await Tinify.FromFile("unoptimized.png")
    .Convert(new { type = new[] { Format.Jxl, Format.WebP } })
    .GetResult();

await result.ToFile($"optimized.{result.Extension}");

The constants are plain strings, so type = "image/jxl" keeps working.

Running tests

dotnet restore
dotnet test test/Tinify.Tests

Integration tests

dotnet restore
TINIFY_KEY=$YOUR_API_KEY dotnet test test/Tinify.Tests.Integration

Or add a .env file to the /test/Tinify.Tests.Integration directory in the format

TINIFY_KEY=<YOUR_API_KEY>

License

This software is licensed under the MIT License. View the license.

Releases

Packages

Used by

Contributors

Languages