{"id":15036277,"url":"https://github.com/ctolkien/tinypng","last_synced_at":"2025-04-06T08:14:36.303Z","repository":{"id":54192290,"uuid":"46763604","full_name":"ctolkien/TinyPNG","owner":"ctolkien","description":".NET Standard wrapper around the tinypng.com image compression service","archived":false,"fork":false,"pushed_at":"2024-08-27T12:43:58.000Z","size":429,"stargazers_count":64,"open_issues_count":0,"forks_count":18,"subscribers_count":5,"default_branch":"main","last_synced_at":"2025-04-06T08:14:29.407Z","etag":null,"topics":["amazon-s3-storage","compress-images","compressing-images","compression","csharp-library","dotnet-core","hacktoberfest","tinypng"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ctolkien.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["ctolkien"]}},"created_at":"2015-11-24T03:07:39.000Z","updated_at":"2024-09-09T17:09:52.000Z","dependencies_parsed_at":"2024-05-31T00:52:31.424Z","dependency_job_id":"7d918efd-bb22-4e53-90aa-28da7bc9335e","html_url":"https://github.com/ctolkien/TinyPNG","commit_stats":{"total_commits":245,"total_committers":7,"mean_commits":35.0,"dds":"0.27755102040816326","last_synced_commit":"c72534208ad37f842dfc79855ee4d0d0bb7cca97"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctolkien%2FTinyPNG","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctolkien%2FTinyPNG/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctolkien%2FTinyPNG/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ctolkien%2FTinyPNG/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ctolkien","download_url":"https://codeload.github.com/ctolkien/TinyPNG/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247451667,"owners_count":20940944,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["amazon-s3-storage","compress-images","compressing-images","compression","csharp-library","dotnet-core","hacktoberfest","tinypng"],"created_at":"2024-09-24T20:30:41.164Z","updated_at":"2025-04-06T08:14:36.284Z","avatar_url":"https://github.com/ctolkien.png","language":"C#","funding_links":["https://github.com/sponsors/ctolkien"],"categories":[],"sub_categories":[],"readme":"# TinyPng for .NET\n\n[![TinyPNG on NuGet](https://img.shields.io/nuget/v/tinypng.svg?maxAge=2000)](https://www.nuget.org/packages/TinyPNG)\n[![MIT license](https://img.shields.io/github/license/ctolkien/TinyPNG.svg?maxAge=2592000)](LICENSE)\n\nThis is a .NET Standard wrapper around the [TinyPNG.com](https://tinypng.com) image compression service. This is not an official TinyPNG.com product.\n\n* Supports .NET Core and full .NET Framework\n* Non-blocking async turtles all the way down\n* `Byte[]`, `Stream`, `File` and `Url` API's available\n\n## Installation\n\nInstall via Nuget\n\n```\nInstall-Package TinyPNG\n```\n\nInstall via `dotnet`\n\n```\ndotnet add package TinyPNG\n```\n\n## Quickstart\n```csharp\nusing var png = new TinyPngClient(\"yourSecretApiKey\");\nvar result = await png.Compress(\"cat.jpg\");\n\n//URL to your compressed version\nresult.Output.Url;\n```\n\n# Version Upgrades\n\n## Upgrading from V3 to V4\n\n* The namespaces have changed for the extension methods to all reside in the `TinyPng` namespace. This will avoid needing to bring in two different namespaces.\n* The `CompressFromUrl` method has been removed. This is now available via a new overload for `Compress` which takes in a `Uri` object\n* I've standardised the namespace on `TinyPng`, it was a bit of a mixed bag of casing previously.\n\n## Upgrading from V2 to V3\n\nThe API has changed from V2, primarily you no longer need to await each individual\nstep of using the TinyPNG API, you can now chain appropriate calls together as\nthe extension methods now operate on `Task\u003cT\u003e`.\n\n## Compressing Images\n\n```csharp\n// create an instance of the TinyPngClient\nusing var png = new TinyPngClient(\"yourSecretApiKey\");\n\n// Create a task to compress an image.\n// this gives you the information about your image as stored by TinyPNG\n// they don't give you the actual bits (as you may want to chain this with a resize\n// operation without caring for the originally sized image).\nvar compressImageTask = png.Compress(\"pathToFile or byte array or stream\");\n// or `CompressFromUrl` if compressing from a remotely hosted image.\nvar compressFromUrlImageTask = png.CompressFromUrl(\"image url\");\n\n// If you want to actually save this compressed image off\n// it will need to be downloaded\nvar compressedImage = await compressImageTask.Download();\n\n// you can then get the bytes\nvar bytes = await compressedImage.GetImageByteData();\n\n// get a stream instead\nvar stream = await compressedImage.GetImageStreamData();\n\n// or just save to disk\nawait compressedImage.SaveImageToDisk(\"pathToSaveImage\");\n\n// Putting it all together\nawait png.Compress(\"path\")\n            .Download()\n            .SaveImageToDisk(\"savedPath\");\n```\n\nFurther details about the result of the compression are also available on the `Input` and `Output` properties of a `Compress` operation. Some examples:\n```csharp\nvar result = await png.Compress(\"pathToFile or byte array or stream\");\n\n// old size\nresult.Input.Size;\n\n// new size\nresult.Output.Size;\n\n// URL of the compressed Image\nresult.Output.Url;\n```\n\n## Resizing Images\n\n```csharp\nusing var png = new TinyPngClient(\"yourSecretApiKey\");\n\nvar compressImageTask = png.Compress(\"pathToFile or byte array or stream\");\n\nvar resizedImageTask = compressImageTask.Resize(width, height);\n\nawait resizedImageTask.SaveImageToDisk(\"pathToSaveImage\");\n\n// altogether now....\nawait png.Compress(\"pathToFile\")\n            .Resize(width, height)\n            .SaveImageToDisk(\"pathToSaveImage\");\n```\n\n### Resize Operations\n\nThere are certain combinations when specifying resize options which aren't compatible with\nTinyPNG. We also include strongly typed resize operations,\ndepending on the type of resize you want to do.\n\n```csharp\nusing var png = new TinyPngClient(\"yourSecretApiKey\");\n\nvar compressTask = png.Compress(\"pathToFile or byte array or stream\");\n\nawait compressTask.Resize(new ScaleWidthResizeOperation(width));\nawait compressTask.Resize(new ScaleHeightResizeOperation(height));\nawait compressTask.Resize(new FitResizeOperation(width, height));\nawait compressTask.Resize(new CoverResizeOperation(width, height));\n```\n\nThe same `Byte[]`, `Stream`, `File` and `Url` path API's are available from the result of the `Resize()` method.\n\n## Converting Formats (v4)\n\nYou can convert images to different formats using the `Convert()` method. This will return a object which contains the converted image data.\n\n```csharp\nusing var png = new TinyPngClient(\"yourSecretApiKey\");\n\nvar compressAndConvert = await png.Compress(\"cat.png\").Convert(ConvertImageFormat.Wildcard);\n```\n\nBy using the `Wildcard` format, TinyPng will return the best type for the supplied image.\n\nIn the scenario that you are converting to an image and losing transparency, you can specify a background colour to use for the image.\n\n```csharp\nvar compressAndConvert = await png.Compress(\"cat.png\").Convert(ConvertImageFormat.Wildcard, \"#FF0000\");\n```\n\n\n## Amazon S3 Storage\n\nThe result of any compress operation can be stored directly on to Amazon S3 storage. I'd strongly recommend referring to [TinyPNG.com's documentation](https://tinypng.com/developers/reference) with regard to how to configure\nthe appropriate S3 access.\n\nIf you're going to be storing images for most requests into S3, then you can pass in an `AmazonS3Configuration` object to the constructor which will be used for all subsequent requests.\n\n```csharp\nusing var png = new TinyPngClient(\"yourSecretApiKey\",\n    new AmazonS3Configuration(\"awsAccessKeyId\", \"awsSecretAccessKey\", \"bucket\", \"region\"));\n\nvar compressedCat = await png.Compress(\"cat.jpg\");\nvar s3Uri = await png.SaveCompressedImageToAmazonS3(compressedCat, \"file-name.png\");\n\n// If you'd like to override the particular bucket or region\n// an image is being stored to from what is specified in the AmazonS3Configuration:\nvar s3UriInNewSpot = await png.SaveCompressedImageToAmazonS3(\n    compressedCat,\n    \"file-name.png\",\n    bucketOverride: \"different-bucket\",\n    regionOverride: \"different-region\");\n```\n\nYou can also pass a `AmazonS3Configuration` object directly into calls to `SaveCompressedImageToAmazonS3`\n\n```csharp\nusing var png = new TinyPngClient(\"yourSecretApiKey\");\nvar compressedCat = await png.Compress(\"cat.jpg\");\nvar s3Uri = await png.SaveCompressedImageToAmazonS3(compressedCat,\n    new AmazonS3Configuration(\n        \"awsAccessKeyId\",\n        \"awsSecretAccessKey\",\n        \"bucket\",\n        \"region\"), \"file-name.png\");\n```\n\n\n## Compression Count\n\nYou can get a read on the number of compression operations you've performed by inspecting the `CompressionCount` property\non the result of any operation you've performed. This is useful for keeping tabs on your API usage.\n\n```csharp\nvar compressedCat = await png.Compress(\"cat.jpg\");\ncompressedCat.CompressionCount; // = 5\n```\n\n## HttpClient\n\nTinyPngClient can take HttpClient as constructor overload, the lifetime of which can be controlled from outside the library.\n\n```csharp\nvar httpClient = new HttpClient();\nvar png = new TinyPngClient(\"yourSecretApiKey\", httpClient);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctolkien%2Ftinypng","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fctolkien%2Ftinypng","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fctolkien%2Ftinypng/lists"}