{"id":18695543,"url":"https://github.com/targetcloud/tgimage","last_synced_at":"2025-04-12T07:25:51.402Z","repository":{"id":56922885,"uuid":"95943523","full_name":"targetcloud/TGImage","owner":"targetcloud","description":"一款以最新潮的方式来使用UIImage的swift插件","archived":false,"fork":false,"pushed_at":"2017-08-10T09:58:37.000Z","size":408,"stargazers_count":18,"open_issues_count":0,"forks_count":3,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-12T05:03:03.985Z","etag":null,"topics":["image","imagemagick","uiimage"],"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/targetcloud.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":"2017-07-01T05:10:47.000Z","updated_at":"2024-09-16T11:04:11.000Z","dependencies_parsed_at":"2022-08-20T22:20:23.692Z","dependency_job_id":null,"html_url":"https://github.com/targetcloud/TGImage","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/targetcloud%2FTGImage","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/targetcloud%2FTGImage/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/targetcloud%2FTGImage/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/targetcloud%2FTGImage/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/targetcloud","download_url":"https://codeload.github.com/targetcloud/TGImage/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248532433,"owners_count":21119909,"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","imagemagick","uiimage"],"created_at":"2024-11-07T11:15:26.041Z","updated_at":"2025-04-12T07:25:51.377Z","avatar_url":"https://github.com/targetcloud.png","language":"Swift","readme":"\u003cimg src=\"https://github.com/targetcloud/TGImage/blob/master/snapShot/Banners.png\" width = \"12%\" hight = \"12%\"/\u003e\n\n# TGImage\n\n一款以最时髦的方式来使用UIImage的swift插件\n\n![Swift](https://img.shields.io/badge/Swift-3.0-orange.svg)\n![Build](https://img.shields.io/badge/build-passing-green.svg)\n![License MIT](https://img.shields.io/badge/license-MIT-green.svg?style=flat)\n![Platform](https://img.shields.io/cocoapods/p/Pastel.svg?style=flat)\n![Cocoapod](https://img.shields.io/badge/pod-v0.0.2-blue.svg)\n\n\n## Features\n- [x] 支持链式编程\n- [x] 支持with 和size两种开启模式\n- [x] 支持+= 、+两种图片相加操作\n- [x] 用例丰富、快速使用\n\n## Usage\n\n#### size开启模式\n\n```swift\nUIImage.size() 或.resizable()\n.color .border .corner\n.image\n.position\n```\n\n\u003e ##### 其中size开启的是固定大小模式、resizable开启的是可变大小模式\n\u003e ##### 其中color支持传入渐变色，如 gradient: [.lightGray, .white], locations: [0, 1], from: CGPoint(x: 0, y: 1), to: CGPoint(x: 0, y: 0)\n\u003e ##### 其中border可以设置color、width、radius、alignment\n\u003e ##### 其中corner可以分别设置4个角或统一设置四个角为同一个值\n\u003e ##### 其中image用于生成 UIImage\n\u003e ##### 其中position用于后面+或+=时用\n\n##### 注意：按上面大的顺序链式编程，在size和image之间的color 、border 、corner没有顺序要求\n\n\nsize开启方式\n\n```swift\nUIImage.size(width: CGFloat, height: CGFloat)\nUIImage.size(_ size: CGSize)\nUIImage.resizable()\n```\n\n#### with CGContext开启模式\n\n支持UIImage.with类方式开启或image.with类实例开启\n\n类方式是返回单图，实例方式开始是在实例图的基础再加上with图，实际是两图相加模式\n\n\nwith开启方式\n\n```swift\nUIImage.with(width: CGFloat, height: CGFloat, block: ContextBlock)//单\nimage.with(size: CGSize, opaque: Bool = false, scale: CGFloat = 0, block: ContextBlock)//相加\nimage.with(_ block: ContextBlock)//单\n```\n\n\n\n\n\n\n\n\n#### 应用场景及Demo(以下图都是用代码绘制的哦)\n\n在cell的某角上放一个某角载剪的渐变图\n\n在某图上再画图\n\n多个图相加放入容器图中\n\n…\n\n#### 1\n\n```swift\nUIImageView(image: ({ () -\u003e UIImage in\n            var container = UIImage.size(width: 180, height: 20)\n                .color(.clear)\n                .image\n            for i in 0..\u003c7{\n                let doti = UIImage.size(width: 20, height: 20)\n                    .color(gradient: [UIColor.randomColor(), UIColor.randomColor()], locations: [0, 1], from: CGPoint(x: 0, y: 0), to: CGPoint(x: 1, y: 1))\n                    .corner(radius: 10)\n                    .image\n                    .position(CGPoint(x: i * 20 + (i + 1) * 3, y: 0))\n                container = container + doti\n            }\n            return container\n        })())\n```\n\n\u003cimg src=\"https://github.com/targetcloud/TGImage/blob/master/snapShot/1.png\" width = \"20%\" hight = \"20%\"/\u003e\n\n\n#### 2\n\n```swift\nUIImageView(image: ({ () -\u003e UIImage in\n            var container = UIImage.size(width: 30, height: 120)\n                .color(.clear)\n                .image\n            for i in 0..\u003c4{\n                let doti = UIImage.size(width: CGFloat(30 - i * 4), height: CGFloat(30 - i * 4))\n                    .color(gradient: [UIColor.randomColor(), UIColor.randomColor()], locations: [0, 1], from: CGPoint(x: 0, y: 0), to: CGPoint(x: 1, y: 1))\n                    .corner(radius: CGFloat(30 - i * 4) * 0.5)\n                    .image\n                    .position(CGPoint(x: i * 2, y: 30 * i + (i + 1) * 3))\n                container += doti\n            }\n            return container\n        })())\n```\n\n\u003cimg src=\"https://github.com/targetcloud/TGImage/blob/master/snapShot/2.png\" width = \"5%\" hight = \"5%\"/\u003e\n\n\n#### 3\n\n```swift\nUIImageView(image:\n            UIImage.size(width: 27, height: 27)\n                .corner(radius: 13.5)\n                .color(.white)\n                .border(color: .lightGray)\n                .border(width: 2)\n                .image\n                .with({ context in\n                    context.setLineCap(.round)\n                    UIColor.lightGray.setStroke()\n                    context.setLineWidth(2)\n                    context.move(to: CGPoint(x: 6, y: 12))\n                    context.addLine(to: CGPoint(x: 9, y: 18))\n                    context.move(to: CGPoint(x: 9, y: 18))\n                    context.addLine(to: CGPoint(x: 21, y: 9))\n                    context.strokePath()\n                })\n        )\n```\n\n\u003cimg src=\"https://github.com/targetcloud/TGImage/blob/master/snapShot/10.png\" width = \"10%\" hight = \"10%\"/\u003e\n\n\n#### 4\n\n```swift\nUIImageView(image: UIImage.size(width: 100, height: 100)\n            .color(gradient: [.green, .blue], locations: [0, 1], from: CGPoint(x: 0, y: 1), to: CGPoint(x: 0, y: 0))\n            .border(gradient: [.red, .yellow], locations: [0, 1], from: CGPoint(x: 0, y: 0), to: CGPoint(x: 1, y: 0))\n            .border(width: 5)\n            .border(alignment: .outside)\n            .corner(topLeft: 20)\n            .corner(topRight: 50)\n            .corner(bottomLeft: 50)\n            .corner(bottomRight: 20)\n            .image)\n```\n\n\u003cimg src=\"https://github.com/targetcloud/TGImage/blob/master/snapShot/4.png\" width = \"10%\" hight = \"10%\"/\u003e\n\n\n#### 5\n\n```swift\nUIImageView(image: ({ () -\u003e UIImage in\n            let background = UIImage.size(width: 120, height: 120)\n                .color(gradient: [.black, .white], locations: [0, 1], from: CGPoint(x: 0, y: 0), to: CGPoint(x: 0, y: 1))\n                .corner(radius: 13.5)\n                .image\n            let circle = UIImage.size(width: 106, height: 106)\n                .color(.white)\n                .corner(radius: 50)\n                .image\n            let center = UIImage.size(width: 8, height: 8)\n                .color(.black)\n                .corner(radius: 3)\n                .image\n            let clock = background + circle + center\n            return clock.with { context in\n                context.setLineCap(.round)\n                UIColor.black.setStroke()\n                context.setLineWidth(2)\n                context.move(to: CGPoint(x: clock.size.width / 2, y: clock.size.height / 2))\n                context.addLine(to: CGPoint(x: clock.size.width / 2 - 5, y: 15))\n                context.move(to: CGPoint(x: clock.size.width / 2, y: clock.size.height / 2))\n                context.addLine(to: CGPoint(x: clock.size.width - 25, y: clock.size.height / 2 - 3))\n                context.strokePath()\n                UIColor.red.setStroke()\n                context.setLineWidth(1)\n                context.move(to: CGPoint(x: clock.size.width / 2 + 8, y: clock.size.height / 2 - 7))\n                context.addLine(to: CGPoint(x: 26, y: clock.size.height / 2 + 35))\n                context.strokePath()\n                UIColor.red.setFill()\n                let rect = CGRect(x: clock.size.width / 2 - 1, y: clock.size.height / 2 - 1, width: 3, height: 3)\n                context.fillEllipse(in: rect)\n            }\n        })())\n```\n\n\u003cimg src=\"https://github.com/targetcloud/TGImage/blob/master/snapShot/5.png\" width = \"10%\" hight = \"10%\"/\u003e\n\n\n#### 6\n\n```swift\nUIImageView(image:\n            ({ () -\u003e UIImage in\n                let circle = UIImage.size(width: 8, height: 8)\n                    .color(.white)\n                    .corner(radius: 4)\n                    .image\n                    .position(CGPoint(x: 5, y: 5))\n                return UIImage.size(width: UIScreen.main.bounds.width*0.5, height: 44)\n                    .color(gradient: [.red, .white], locations: [0, 1], from: CGPoint(x: 0, y: 0), to: CGPoint(x: 1, y: 1))\n                    .corner(bottomRight: 20)\n                    .image + circle\n            })())\n```\n\n\u003cimg src=\"https://github.com/targetcloud/TGImage/blob/master/snapShot/6.png\" width = \"10%\" hight = \"10%\"/\u003e\n\n\n```swift\nUIImageView(image:\n            ({ () -\u003e UIImage in\n                let circle = UIImage.size(width: 8, height: 8)\n                    .color(.white)\n                    .corner(radius: 4)\n                    .image\n                    .position(CGPoint(x: UIScreen.main.bounds.width * 0.5 - 15, y: 5))\n                return UIImage.size(width: UIScreen.main.bounds.width*0.5, height: 44)\n                    .color(gradient: [.white, .lightGray], locations: [0, 1], from: CGPoint(x: 0, y: 0), to: CGPoint(x: 1, y: 1))\n                    .corner(bottomLeft: 20)\n                    .image + circle\n            })())\n```\n\n\u003cimg src=\"https://github.com/targetcloud/TGImage/blob/master/snapShot/7.png\" width = \"10%\" hight = \"10%\"/\u003e\n\n\n```swift\nUIImageView(image:\n            ({ () -\u003e UIImage in\n                return UIImage.size(width: UIScreen.main.bounds.width*0.5, height: 44)\n                    .color(gradient: [.white, UIColor.randomColor().withAlphaComponent(0.5)], locations: [0, 1], from: CGPoint(x: 0, y: 0), to: CGPoint(x: 1, y: 1))\n                    .corner(topLeft: 20)\n                    .image\n            })())\n```\n\n\u003cimg src=\"https://github.com/targetcloud/TGImage/blob/master/snapShot/8.png\" width = \"10%\" hight = \"10%\"/\u003e\n\n\n```swift\nUIImageView(image:\n            ({ () -\u003e UIImage in\n                return UIImage.size(width: UIScreen.main.bounds.width*0.5, height: 22)\n                    .color(gradient: [UIColor.randomColor(), .white], locations: [0, 1], from: CGPoint(x: 0, y: 0), to: CGPoint(x: 1, y: 1))\n                    .corner(topLeft: 10)\n                    .image\n            })())\n            \nUIImageView(image:\n            ({ () -\u003e UIImage in\n                return UIImage.size(width: UIScreen.main.bounds.width*0.5, height: 22)\n                    .color(gradient: [.lightGray, .white], locations: [0, 1], from: CGPoint(x: 0, y: 0), to: CGPoint(x: 1, y: 1))\n                    .corner(bottomLeft: 10)\n                    .image\n            })())\n```\n\n\u003cimg src=\"https://github.com/targetcloud/TGImage/blob/master/snapShot/9.png\" width = \"10%\" hight = \"10%\"/\u003e\n\n\n#### 更多使用配置组合效果请download本项目或fork本项目查看\n\n## Installation\n- 下载并拖动TGImage.swift到你的工程中\n\n- Cocoapods\n```\npod 'TGImage'\n```\n\n## Reference\n- http://blog.csdn.net/callzjy\n- https://github.com/targetcloud/baisibudejie\n- https://github.com/targetcloud/TGRefreshSwift \u003cimg src=\"https://github.com/targetcloud/TGRefreshSwift/blob/master/logo.png\" width = \"12%\" hight = \"12%\"/\u003e\n- https://github.com/targetcloud/TGLabel \u003cimg src=\"https://github.com/targetcloud/TGLabel/blob/master/Banners.png\" width = \"12%\" hight = \"12%\"/\u003e\n- https://github.com/targetcloud/TGPhotoPicker\u003cimg src=\"https://github.com/targetcloud/TGPhotoPicker/blob/master/logo.png\" width = \"12%\" hight = \"12%\"/\u003e\n\n\n如果你觉得赞，请Star\n\u003cimg src=\"https://github.com/targetcloud/TGImage/blob/master/snapShot/logo.png\" width = \"12%\" hight = \"12%\"/\u003e\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftargetcloud%2Ftgimage","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftargetcloud%2Ftgimage","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftargetcloud%2Ftgimage/lists"}