{"id":13872191,"url":"https://github.com/tayloraswift/swift-png","last_synced_at":"2025-12-11T23:01:50.923Z","repository":{"id":50553675,"uuid":"80696537","full_name":"tayloraswift/swift-png","owner":"tayloraswift","description":"decode, inspect, edit, and encode png images in pure swift","archived":false,"fork":false,"pushed_at":"2025-01-16T00:26:18.000Z","size":170023,"stargazers_count":384,"open_issues_count":18,"forks_count":40,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-01T09:21:15.595Z","etag":null,"topics":["deflate","image-decoder","image-encoder","image-processing","lz77","png","png-decoder","png-encoder","swift"],"latest_commit_sha":null,"homepage":"https://swiftinit.org/docs/swift-png","language":"Swift","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/tayloraswift.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":["tayloraswift"]}},"created_at":"2017-02-02T05:29:56.000Z","updated_at":"2025-03-29T10:16:01.000Z","dependencies_parsed_at":"2024-12-08T11:03:13.255Z","dependency_job_id":"beeefc97-7d87-4bf6-a3b4-72cf7d5d966c","html_url":"https://github.com/tayloraswift/swift-png","commit_stats":null,"previous_names":["kelvin13/swift-png","kelvin13/png"],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tayloraswift%2Fswift-png","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tayloraswift%2Fswift-png/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tayloraswift%2Fswift-png/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tayloraswift%2Fswift-png/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tayloraswift","download_url":"https://codeload.github.com/tayloraswift/swift-png/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247821032,"owners_count":21001604,"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":["deflate","image-decoder","image-encoder","image-processing","lz77","png","png-decoder","png-encoder","swift"],"created_at":"2024-08-05T23:00:36.215Z","updated_at":"2025-12-11T23:01:43.116Z","avatar_url":"https://github.com/tayloraswift.png","language":"Swift","funding_links":["https://github.com/sponsors/tayloraswift"],"categories":["Swift"],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n\n***`png`***\n\n[![Tests](https://github.com/tayloraswift/swift-png/actions/workflows/Tests.yml/badge.svg)](https://github.com/tayloraswift/swift-png/actions/workflows/Tests.yml)\n[![Documentation](https://github.com/tayloraswift/swift-png/actions/workflows/Documentation.yml/badge.svg)](https://github.com/tayloraswift/swift-png/actions/workflows/Documentation.yml)\n\n\u003c/div\u003e\n\n*Swift PNG* is a Foundation-less, cross-platform framework for decoding, inspecting, editing, and encoding PNG images. The framework is written in pure Swift, and will compile and provide consistent behavior on all Swift platforms. The library also comes with built-in file system support on linux, macOS, and Windows.\n\nThe library is powered by a native Swift *DEFLATE* implementation, which can be used as a [standalone module](https://swiftinit.org/docs/swift-png/lz77).\n\nSwift *PNG* is [available](LICENSE) under the [Apache 2.0 license](https://www.apache.org/licenses/LICENSE-2.0). The [example programs](Snippets/) are public domain and can be adapted freely.\n\nSwift *PNG*’s [documentation](https://swiftinit.org/docs/swift-png/png) is available on Swiftinit!\n\n\n## Requirements\n\nThe swift-png library requires Swift 5.10 or later.\n\n| Platform | Status |\n| -------- | ------ |\n| 🐧 Linux | [![Tests](https://github.com/tayloraswift/swift-png/actions/workflows/Tests.yml/badge.svg)](https://github.com/tayloraswift/swift-png/actions/workflows/Tests.yml) |\n| 🍏 Darwin | [![Tests](https://github.com/tayloraswift/swift-png/actions/workflows/Tests.yml/badge.svg)](https://github.com/tayloraswift/swift-png/actions/workflows/Tests.yml) |\n| 🍏 Darwin (iOS) | [![iOS](https://github.com/tayloraswift/swift-png/actions/workflows/iOS.yml/badge.svg)](https://github.com/tayloraswift/swift-png/actions/workflows/iOS.yml) |\n| 🍏 Darwin (tvOS) | [![tvOS](https://github.com/tayloraswift/swift-png/actions/workflows/tvOS.yml/badge.svg)](https://github.com/tayloraswift/swift-png/actions/workflows/tvOS.yml) |\n| 🍏 Darwin (visionOS) | [![visionOS](https://github.com/tayloraswift/swift-png/actions/workflows/visionOS.yml/badge.svg)](https://github.com/tayloraswift/swift-png/actions/workflows/visionOS.yml) |\n| 🍏 Darwin (watchOS) | [![watchOS](https://github.com/tayloraswift/swift-png/actions/workflows/watchOS.yml/badge.svg)](https://github.com/tayloraswift/swift-png/actions/workflows/watchOS.yml) |\n\n\n[Check deployment minimums](https://swiftinit.org/docs/swift-png#ss:platform-requirements)\n\n\n## Getting started\n\nTo use *Swift PNG* in a project, add this descriptor to the `dependencies` list in your `Package.swift` file:\n\n```swift\n.package(url: \"https://github.com/tayloraswift/swift-png\", .from(\"4.4.0\"))\n```\n\n## Basic usage\n\nDecode an image:\n\n```swift\nimport PNG\nfunc decode(png path:String) throws\n{\n    guard\n    let image:PNG.Image = try .decompress(path: path)\n    else\n    {\n        // failed to access file from file system\n    }\n\n    let rgba:[PNG.RGBA\u003cUInt8\u003e] = image.unpack(as: PNG.RGBA\u003cUInt8\u003e.self),\n        size:(x:Int, y:Int)    = image.size\n    // ...\n}\n```\n\nEncode an image:\n\n```swift\nfunc encode(png path:String, size:(x:Int, y:Int), pixels:[PNG.RGBA\u003cUInt8\u003e]) throws\n{\n    let image:PNG.Image = .init(packing: pixels, size: size,\n        layout: .init(format: .rgba8(palette: [], fill: nil)))\n    try image.compress(path: path, level: 9)\n}\n```\n\n## Features\n\n- ***Powerful interfaces.*** *Swift PNG*’s expressive, strongly-typed APIs make working with PNG images easy for beginners and advanced users alike. If your code compiles, you’re already most of the way there. Power users can take advantage of [custom indexing](https://swiftinit.org/docs/swift-png/png/indexing), [manual decoding workflows](https://swiftinit.org/docs/swift-png/png/onlinedecoding), and [user-defined color targets](https://swiftinit.org/docs/swift-png/png/customcolor).\n\n- ***Superior compression***. *Swift PNG* supports minimum cost path-based [*DEFLATE*](https://tools.ietf.org/html/rfc1951) optimization, which is why it offers four additional compression levels beyond what [*libpng*](http://www.libpng.org/pub/png/libpng.html) supports.\n\n- ***Competitive performance.*** *Swift PNG* offers competitive performance compared to *libpng*. On appropriate CPU architectures, the *Swift PNG* encoder makes use of [hardware-accelerated hash tables](https://engineering.fb.com/2019/04/25/developer-tools/f14/) for even greater performance.\n\n- ***Pure Swift, all the way down.*** *Swift PNG* is powered by its own, native Swift *DEFLATE* implementation. It depends only on other Foundation-less, pure-Swift libraries, and therefore does not need to link Foundation. This also means the core components of *Swift PNG* work on any platform that Swift itself works on, and that *Swift PNG*’s performance improves as the Swift compiler matures.\n\n- ***Batteries included.*** *Swift PNG* comes with [built-in color targets](https://swiftinit.org/ptcl/swift-png/png/_pngcolor) with support for [premultiplied alpha](https://swiftinit.org/docs/swift-png/png/png/rgba.premultiplied). [Convolution](https://swiftinit.org/docs/swift-png/png/png.convolve(_:dereference:kernel:)?hash=O92V) and [deconvolution](https://swiftinit.org/docs/swift-png/png/png.deconvolve(_:as:depth:kernel:)?hash=2SQA0) helper functions make [implementing custom color targets](https://swiftinit.org/docs/swift-png/png/customcolor) a breeze.\n\n- ***First-class iPhone optimization support.*** *Swift PNG* requires no custom setup or third-party plugins to handle [iPhone-optimized](https://swiftinit.org/docs/swift-png/png/iphoneoptimized) PNG images. iPhone-optimized images just work, on all platforms. Reproduce [`pngcrush`](https://developer.apple.com/library/archive/qa/qa1681/_index.html)’s output with [bit width-aware alpha premultiplication](https://swiftinit.org/docs/swift-png/png/png/rgba.premultiplied(as:)), for seamless integration anywhere in your application stack.\n\n- ***Comprehensive metadata support.*** *Swift PNG* can parse and validate all public PNG chunks, which are accessible as [strongly-typed metadata records](https://swiftinit.org/docs/swift-png/png/png/metadata).\n\n- ***Modern error handling.*** *Swift PNG* has a fully stateless and Swift-native [error-handling system](https://swiftinit.org/docs/swift-png/png/png/error).\n\n## See also\n\n* [Swift *JPEG*](https://github.com/tayloraswift/jpeg)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftayloraswift%2Fswift-png","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftayloraswift%2Fswift-png","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftayloraswift%2Fswift-png/lists"}