{"id":18031725,"url":"https://github.com/dagronf/swiftimagereadwrite","last_synced_at":"2025-03-27T05:30:53.896Z","repository":{"id":165076251,"uuid":"640466887","full_name":"dagronf/SwiftImageReadWrite","owner":"dagronf","description":"A basic microframework of routines for doing basic importing/exporting of `CGImage` and `NSImage`/`UIImage` type images.","archived":false,"fork":false,"pushed_at":"2024-11-07T01:52:00.000Z","size":185,"stargazers_count":21,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-23T04:31:37.000Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Swift","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/dagronf.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"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}},"created_at":"2023-05-14T07:22:41.000Z","updated_at":"2025-03-10T11:36:01.000Z","dependencies_parsed_at":null,"dependency_job_id":"47d233cb-3d26-4852-bd00-7074dd67dc12","html_url":"https://github.com/dagronf/SwiftImageReadWrite","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FSwiftImageReadWrite","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FSwiftImageReadWrite/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FSwiftImageReadWrite/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dagronf%2FSwiftImageReadWrite/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dagronf","download_url":"https://codeload.github.com/dagronf/SwiftImageReadWrite/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245791331,"owners_count":20672665,"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":[],"created_at":"2024-10-30T10:10:35.237Z","updated_at":"2025-03-27T05:30:53.883Z","avatar_url":"https://github.com/dagronf.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SwiftImageReadWrite\n\nA basic Swift microframework of routines for doing basic importing/exporting of `CGImage` and `NSImage`/`UIImage` type images.\n\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/v/tag/dagronf/SwiftImageReadWrite\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/License-MIT-lightgrey\" /\u003e\n    \u003ca href=\"https://swift.org/package-manager\"\u003e\n        \u003cimg src=\"https://img.shields.io/badge/spm-compatible-brightgreen.svg?style=flat\" alt=\"Swift Package Manager\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/pod-compatible-red\" /\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\u003cp align=\"center\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/macOS-10.11+-red\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/iOS-13+-blue\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/tvOS-13+-orange\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/watchOS-6+-brightgreen\" /\u003e\n    \u003cimg src=\"https://img.shields.io/badge/macCatalyst-1.0+-purple\" /\u003e\n\u003c/p\u003e\n\n## Why?\n\nSometimes all you need is to be able load and save basic image data in different formats. \nThis framework provides a basic wrapper around the common use cases.\n\nApple's built in image types are incredibly capable but can be quite verbose to do basic import and export to \ndifferent image file types. It's also somewhat tricky to get basic export correct, so this framework abstracts that\naway with a type-safe, format safe way.\n\nThere are also differences between macOS and the rest of the Apple ecosystem when it comes to converting platform\nimages and this library abstracts those differences away. The same API will work on macOS/iOS/watchOS and tvOS.\n\nIt also provides `Codable` wrapper implementations for CGImage/NSImage/UIImage \n(`CGImageCodable`, `PlatformImageCodable`) to allow easy embedding of images in your `Codable` objects.\n\n[Online documentation](https://swiftpackageindex.com/dagronf/SwiftImageReadWrite/main/documentation/swiftimagereadwrite)\n\n## Supported types\n\n* PNG\n* JPEG\n* TIFF\n* GIF\n* HEIC\n* PDF\n* SVG \n\n## Loading a CGImage\n\nTwo static methods have been added to `CGImage`\n\n```swift\n// Load a CGImage from raw data\nlet image = try CGImage.load(data: \u003csomeData\u003e)\n```\n\n```swift\n// Load a CGImage from a local file on disk\nlet image = try CGImage.load(fileURL: \u003csomeURL\u003e)\n```\n\n```swift\n// Load a CGImage from a named image asset\nlet image = try CGImage.named(\"my_image_name\")\n```\n\n## Generating different image representations\n\nAll the encoding/conversion calls are wrapped inside `representation` on an image object. This was done to \navoid clashing with the platform image calls of similar names.\n\nFor example :-\n\n```swift\nlet image = CGImage/UIImage/NSImage\n\n// Generate a PNG representation\nlet pngData = try image.representation.png(scale: 2)\n\n// Generate a JPG representation at 3x\nlet jpegData = try image.representation.jpeg(scale: 3, compression: 0.65, excludeGPSData: true)\n\n// Generate a PDF representation\nlet pdfData = try image.representation.pdf(size: CGSize(width: 300, height: 300))\n```\n\n## Basic examples\n\n### CGImage\n\n```swift\n// Load a CGImage from raw data\nlet cgImage = try CGImage.load(data: data)\n\n// Export the image as JPG data\nlet jpegData = try cgImage.representation.jpeg(scale: 3, compression: 0.65, excludeGPSData: true)\n\n// Export the image as PNG data\nlet pngData = try cgImage.representation.png(scale: 2)\n\n// Generate an NSImage\nlet nsImage = cgImage.nsImage(scale: 2)\n\n// Generate an UIImage\nlet nsImage = cgImage.uiImage()\n```\n\n### NSImage/UIImage\n\n#### Generating an `NSImage` or `UIImage` representation for a `CGImage`\n\n```swift\n// Load a CGImage from raw data\nlet cgImage = CGImage.load(data: data)\n\n// Convert to an NSImage\nlet nsImage = cgImage.nsImage(scale: 2)\n\n// Convert to a UIImage\nlet uiImage = cgImage.uiImage(scale: 3)\n\n// Generate a PDF representation of the pdf\nlet pdf = try cgImage.representation.pdf()\n```\n\n#### Common routines for loading an `NSImage` or `UIImage`\n\n```swift\n// This loads an `NSImage` or `UIImage` depending on the current platform \nlet platformImage = PlatformImage.load(data: data)\n\n// This loads an `NSImage` or `UIImage` depending on the current platform\nlet platformImage = PlatformImage.load(fileURL: \u003csome url\u003e)\n```\n\n### SwiftUI\n\n```swift\n// Load a CGImage from raw data\nlet cgImage = CGImage.load(data: data)\n\n// Create a SwiftUI image with this image\nlet swiftUIImage = cgImage.representation.swiftUI(scale: 2, label: Text(\"My Image\"))\n```\n\n## Converting colorspaces\n\nThis library provides basic colorspace conversion to CMYK, Gray and sRGB.  \n\n```swift\nlet cmykImage = try image.convertColorspace.genericCMYK()\nlet grayImage = try image.convertColorspace.deviceGray()\nlet sRGBImage = try image.convertColorspace.sRGB()\n```\n\n## Limitations\n\n* `NSImage` supports multiple image representations within a single image. These routines only deal with a single\nrepresentation, so an image with multiple stored representations will only ever deal with the 'best' representation.\n\n# License\n\n```\nMIT License\n\nCopyright (c) 2024 Darren Ford\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdagronf%2Fswiftimagereadwrite","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdagronf%2Fswiftimagereadwrite","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdagronf%2Fswiftimagereadwrite/lists"}