Tinify.Unofficial
1.0.2
See the version list below for details.
dotnet add package Tinify.Unofficial --version 1.0.2
NuGet\Install-Package Tinify.Unofficial -Version 1.0.2
<PackageReference Include="Tinify.Unofficial" Version="1.0.2" />
paket add Tinify.Unofficial --version 1.0.2
#r "nuget: Tinify.Unofficial, 1.0.2"
// Install Tinify.Unofficial as a Cake Addin #addin nuget:?package=Tinify.Unofficial&version=1.0.2 // Install Tinify.Unofficial as a Cake Tool #tool nuget:?package=Tinify.Unofficial&version=1.0.2
Unofficial fork of the 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.
Installation
Install the API client:
Install-Package Tinify.Unofficial
Usage
using Tinify.Unofficial;
var client = new TinifyClient("YOUR_API_KEY");
await using var optimizedImage = await client.ShrinkFromFile("unoptimized.png");
await optimizedImage.ToFileAsync("optimized.png");
To perform other transform operations, simply call the TransformImage
method
on the optimized image
await using var optimizedImage = await client.ShrinkFromFile("unoptimized.jpg");
var resizeOptions = new ResizeOperation(ResizeType.Fit, 50, 20);
var preserveOptions = new PreserveOperation(PreserveOptions.Copyright | PreserveOptions.Creation);
var transformOperations = new TransformOperations(resize: resizeOptions, preserve: preserveOptions);
await using var result = await optimizedImage.TransformImage(transformOperations);
await result.ToFileAsync("optimized_and_transformed.jpg");
You can save both OptimizedImage
and ImageResult
objects to a file, to a stream, to a buffer or pass in a
preallocated buffer and copy the data directly to the buffer
await using var optimizedImage = await client.ShrinkFromFile("unoptimized.jpg");
await using var transformedImage =
await optimizedImage.TransformImage(new TransformOperations(
resize: new ResizeOperation(ResizeType.Fit, 50, 20)
));
var optimizedBuffer = await optimizedImage.ToBufferAsync();
// Note the ImageResult object already holds an internal buffer
// with the image data and so will just return a copy synchronously
var transformedBuffer = transformedImage.ToBuffer();
using var msOptimized = new MemoryStream();
await optimizedImage.ToStreamAsync(msOptimized);
using var msTransformed = new MemoryStream();
await transformedImage.ToStreamAsync(msTransformed);
var bufferOptimized = new byte[optimizedImage.ImageSize.Value];
await optimizedImage.CopyToBufferAsync(bufferOptimized);
// Note the ImageResult object already holds an internal buffer
// with the image data and so will just copy the data synchronously
var bufferTransformed = new byte[transformedImage.DataLength];
transformedImage.CopyToBuffer(bufferTransformed);
Note:
Because both OptimizedImage
and ImageResult
objects maintain an internal buffer
of the image data, which has been rented from the ArrayPool,
you should be sure to Dispose
of them so that the buffer is returned to the pool.
Both objects implement both IDisposable
and IAsyncDisposable
so that they
can be easily wrapped in either using blocks or statements.
Running tests
dotnet restore
dotnet test test/Tinify.Unofficial.Tests
Integration tests
dotnet restore
TINIFY_KEY=$YOUR_API_KEY dotnet test test/Tinify.Unofficial.Tests.Integration
Or add a .env
file to the /test/Tinify.Unofficial.Tests.Integration
directory in the format
TINIFY_KEY=<YOUR_API_KEY>
License
This software is licensed under the MIT License. View the license.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. |
.NET Core | netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.1 is compatible. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.1
- CommunityToolkit.HighPerformance (>= 8.0.0)
- StandardSocketsHttpHandler (>= 2.2.0.4)
- System.Text.Json (>= 6.0.5)
-
net6.0
- CommunityToolkit.HighPerformance (>= 8.0.0)
- System.Text.Json (>= 6.0.5)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated | |
---|---|---|---|
1.0.3 | 11,607 | 10/28/2022 | |
1.0.3-prerelease.18 | 125 | 10/28/2022 | |
1.0.2 | 375 | 10/26/2022 |
## 1.0.1
* Forked official Tinify repo at version 1.5.3
* MultiTargers .Net Standard 2.1 and .Net 6.0
* Modernized code and added memory and performance enhancements
* Added support for the Tinify convert operation