{"id":15028431,"url":"https://github.com/devxoul/swiftyimage","last_synced_at":"2025-05-16T09:04:05.494Z","repository":{"id":34978596,"uuid":"39057611","full_name":"devxoul/SwiftyImage","owner":"devxoul","description":"🎨 Generate image resources in Swift","archived":false,"fork":false,"pushed_at":"2022-02-17T03:14:09.000Z","size":84,"stargazers_count":1087,"open_issues_count":3,"forks_count":65,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-05-16T09:04:04.352Z","etag":null,"topics":["image","swift"],"latest_commit_sha":null,"homepage":"","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/devxoul.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}},"created_at":"2015-07-14T06:23:58.000Z","updated_at":"2025-05-12T15:59:33.000Z","dependencies_parsed_at":"2022-09-25T03:40:23.557Z","dependency_job_id":null,"html_url":"https://github.com/devxoul/SwiftyImage","commit_stats":null,"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FSwiftyImage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FSwiftyImage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FSwiftyImage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/devxoul%2FSwiftyImage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/devxoul","download_url":"https://codeload.github.com/devxoul/SwiftyImage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254501557,"owners_count":22081528,"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":["image","swift"],"created_at":"2024-09-24T20:08:18.904Z","updated_at":"2025-05-16T09:04:05.466Z","avatar_url":"https://github.com/devxoul.png","language":"Swift","funding_links":[],"categories":[],"sub_categories":[],"readme":"SwiftyImage\n===========\n\n![Swift](https://img.shields.io/badge/Swift-5.0-orange.svg)\n[![CocoaPods](http://img.shields.io/cocoapods/v/SwiftyImage.svg?style=flat)](https://cocoapods.org/pods/SwiftyImage)\n[![CI](https://github.com/devxoul/SwiftyImage/workflows/CI/badge.svg)](http://github.com/devxoul/SwiftyImage/actions)\n\nThe most sexy way to use images in Swift.\n\n\nFeatures\n--------\n\n* [x] [Create images with method chaining](#getting-started)\n* [x] [Gradient fill and stroke](#methods-available)\n* [x] [Create and manipulate images with CGContext](#play-with-cgcontext)\n* [x] [Combine images with `+` operator](#image-operator)\n* [x] iOS support\n* [ ] macOS support\n\n\nAt a Glance\n-----------\n\n##### Creating Images\n\n```swift\nUIImage.size(width: 100, height: 100)\n  .color(.white)\n  .border(color: .red)\n  .border(width: 10)\n  .corner(radius: 20)\n  .image\n```\n\n![sample1](https://cloud.githubusercontent.com/assets/931655/8675848/106e59ea-2a81-11e5-8e4f-98cfea38bd8e.png)\n\n\n```swift\nUIImage.resizable()\n  .color(.white)\n  .border(color: .blue)\n  .border(width: 5)\n  .corner(radius: 10)\n  .image\n```\n\n![sample2](https://cloud.githubusercontent.com/assets/931655/8675936/514b7f60-2a81-11e5-8806-26036d8e8ba5.png)\n\n##### Creating Color Overlayed Image\n\n```swift\nlet image = UIImage(named: \"myArrow\").with(color: UIColor.blueColor())\n```\n\n\nGetting Started\n---------------\n\nSwiftyImage provides a simple way to create images with method chaining.\n\n\n#### Step 1. Start Chaining\n\nMethod chaining starts from `UIImage.size()` or `UIImage.resizable()`.\n\n```swift\nUIImage.size(width: CGFloat, height: CGFloat) // ...\nUIImage.size(size: CGSize) // ...\nUIImage.resizable() // ...\n```\n\n\n#### Step 2. Setting Properties\n\nYou can set fill color, border attributes, corner radius, etc.\n\n```swift\nUIImage.size(width: 100, height: 100)  // fixed size\n  .color(.white)                       // fill color\n  .border(color: .red)                 // border color\n  .border(width: 10)                   // border width\n  .corner(radius: 20)                  // corner radius\n```\n\n```swift\nUIImage.resizable() // resizable image\n  .color(.white)\n  .border(color: .lightGray)\n  .border(width: 1)\n  .corner(radius: 5)\n```\n\n\n#### Step 3. Generating Image\n\nUse `.image` at the end of method chaining to generate image.\n\n```swift\nimageView.image = UIImage.size(width: 100, height: 100)\n  .color(.white)\n  .border(color: .red)\n  .border(width: 10)\n  .corner(radius: 20)\n  .image  // generate UIImage\n```\n\n\n### Methods Available\n\n#### Starting Method Chaining\n\n* **`.size(width: CGFloat, height: CGFloat)`**\n\n    Starts chaining for fixed size image\n\n* **`.size(CGSize)`**\n\n    Starts chaining for fixed size image\n\n* **`.resizable()`**\n\n    Starts chaining for resizable image\n\n#### Setting Properties\n\n* **`.color(UIColor)`**\n\n    Sets fill color\n\n* **`.color(gradient: [UIColor], locations: [CGFloat], from: CGPoint, to: CGPoint)`**\n\n    Sets gradient fill color\n\n    *New in version 1.1.0*\n\n* **`.border(width: CGFloat)`**\n\n    Sets border width\n\n* **`.border(color: UIColor)`**\n\n    Sets border color\n\n* **`.border(gradient: [UIColor], locations: [CGFloat], from: CGPoint, to: CGPoint)`**\n\n    Sets gradient border color\n\n    *New in version 1.1.0*\n\n* **`.border(alignment: BorderAlignment)`**\n\n    Sets border alignment. Same with Photoshop's\n    \n    available values: `.inside`, `.center`, `.outside`\n\n* **`.corner(radius: CGFloat)`**\n\n    Sets all corners radius of image\n\n* **`.corner(topLeft: CGFloat)`**\n\n    Sets top left corner radius of image\n\n* **`.corner(topRight: CGFloat)`**\n\n    Sets top right corner radius of image\n\n* **`.corner(bottomLeft: CGFloat)`**\n\n    Sets bottom left corner radius of image\n\n* **`.corner(bottomRight: CGFloat)`**\n\n    Sets bottom right corner radius of image\n\n#### Generating Image\n\n* **`.image`**\n\n    Generates and returns image\n\n\nPlay with CGContext\n-------------------\n\nSwiftyImage also provides a simple method to create or manipulate images with CGContext.\n\n#### Creating Images\n\n```swift\nlet image = UIImage.with(size: CGSize(width: 100, height: 100)) { context in\n  UIColor.lightGrayColor().setFill()\n  CGContextFillEllipseInRect(context, CGRect(x: 0, y: 0, width: 100, height: 100))\n}\n```\n\n\n#### Manipulating Images\n\n```swift\nlet newImage = oldImage.with { context in\n  UIColor.lightGrayColor().setFill()\n  CGContextFillEllipseInRect(context, CGRect(x: 0, y: 0, width: 100, height: 100))\n}\n```\n\n\nImage Operator\n--------------\n\nYou can easily combine multiple images with `+` operator.\n\n```swift\nlet backgroundImage = ...\nlet iconImage = ...\nlet combinedImage = backgroundImage + iconImage\n```\n\n![combine](https://cloud.githubusercontent.com/assets/931655/8679414/84fb8e5e-2a95-11e5-89ea-8cfbb7ec761d.png)\n\n\nInstallation\n------------\n\n```ruby\npod 'SwiftyImage', '~\u003e 1.1'\n```\n\nPlayground\n----------\n\nUse CocoaPods command `$ pod try SwiftyImage` to try Playground!\n\n![playground](https://cloud.githubusercontent.com/assets/931655/8679576/611e1b9a-2a96-11e5-9f34-debb222f28c6.png)\n\n\nLicense\n-------\n\nSwiftyImage is under MIT license. See the LICENSE file for more info.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevxoul%2Fswiftyimage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevxoul%2Fswiftyimage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevxoul%2Fswiftyimage/lists"}