├── DPImageGenerator ├── DPImageGenerator.swift └── GradientView.swift ├── LICENSE ├── LogoGenerator.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ ├── dwipp.xcuserdatad │ │ └── UserInterfaceState.xcuserstate │ │ └── putra27kenji.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ ├── dwipp.xcuserdatad │ └── xcschemes │ │ ├── LogoGenerator.xcscheme │ │ └── xcschememanagement.plist │ └── putra27kenji.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── LogoGenerator.xcscheme │ └── xcschememanagement.plist ├── LogoGenerator ├── AppDelegate.swift ├── Assets.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Base.lproj │ ├── LaunchScreen.storyboard │ └── Main.storyboard ├── DPImageGenerator │ ├── DPImageGenerator.swift │ └── GradientView.swift ├── Info.plist └── ViewController.swift └── README.md /DPImageGenerator/DPImageGenerator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DPImageGenerator.swift 3 | // LogoGenerator 4 | // 5 | // Created by Dwi Putra on 11/10/15. 6 | // Copyright © 2015 dwipp. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | // Enum for selecting max character allowed inside of image 12 | enum maxCharacter { 13 | case one 14 | case two 15 | } 16 | 17 | class DPImageGenerator: NSObject { 18 | var image_frame:CGRect? 19 | var text_color:UIColor? 20 | var text_font:UIFont? 21 | var max_char:maxCharacter = .two 22 | var dynamic_gradient:Bool = true 23 | 24 | 25 | /* 26 | * This is a view buider. 27 | * Holding selected random gradient color and first character of every words 28 | * params text --> to input the text 29 | * params isDynamic --> an option for dynamic gradient 30 | * return UIView 31 | */ 32 | private func viewBuilder(text:String, isDynamic:Bool) -> UIView { 33 | let color1:[String] = ["EF4DB6", "52EDC7", "55EFCB", "0D77EF", "5AD427", "87FC70", "FF9500", "C86EDF", "55EFCB"] 34 | let color2:[String] = ["C643FC", "5AC8FB", "5BCAFF", "81F3FD", "A4E786", "0BD318", "FF5E3A", "E4B7F0", "5BCAFF"] 35 | 36 | let x:Int? 37 | if isDynamic { 38 | x = Int(arc4random_uniform(UInt32(color1.count))) 39 | }else { 40 | srandom(UInt32(text.characters.count)) 41 | x = Int(random()%color1.count) 42 | } 43 | 44 | let defaultView = UIView(frame: image_frame!) 45 | let gradient: GradientView = GradientView() 46 | 47 | let colors:[UIColor] = [self.colorWithHexString(color1[x!]), self.colorWithHexString(color2[x!])] 48 | 49 | gradient.frame = defaultView.bounds 50 | gradient.colors = colors 51 | gradient.locations = [0.0 , 1.0] 52 | defaultView.addSubview(gradient) 53 | 54 | let width_value = ((image_frame?.width)! - 20) 55 | let height_value = ((image_frame?.height)! / 2) 56 | let x_value = ((image_frame?.width)! - width_value)/2 57 | let y_value = ((image_frame?.height)! - height_value)/2 58 | 59 | let initialName:UILabel = UILabel(frame: CGRectMake(x_value, y_value, width_value, height_value)) 60 | var first_letter:String? 61 | let first_character:NSMutableString = NSMutableString() 62 | let words:[NSString] = text.componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceCharacterSet()) 63 | 64 | var count=0 65 | for word in words { 66 | if word.length > 0 && count < self.getMaxChar(max_char) { 67 | first_letter = word.substringToIndex(1) 68 | first_character.appendString((first_letter?.uppercaseString)!) 69 | count++ 70 | } 71 | } 72 | initialName.text = first_character as String 73 | initialName.textColor = self.getTextColor(self.text_color) 74 | initialName.textAlignment = NSTextAlignment.Center 75 | initialName.font = self.getTextFont(self.text_font) 76 | defaultView.addSubview(initialName) 77 | return defaultView 78 | } 79 | 80 | private func getMaxChar(max:maxCharacter) -> Int { 81 | switch max{ 82 | case .one : 83 | return 1 84 | case .two : 85 | return 2 86 | } 87 | } 88 | 89 | private func getTextColor(color:UIColor?) -> UIColor { 90 | if color != nil { 91 | return color! 92 | }else { 93 | return UIColor.whiteColor() 94 | } 95 | } 96 | 97 | private func getTextFont(font:UIFont?) -> UIFont { 98 | if font != nil { 99 | return font! 100 | }else { 101 | return UIFont.systemFontOfSize(70) 102 | } 103 | } 104 | 105 | /* 106 | * This method will convert hex color to be RGB color. 107 | * params hex --> hex color in string value 108 | * return UIColor 109 | */ 110 | private func colorWithHexString (hex:String) -> UIColor { 111 | var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).uppercaseString 112 | 113 | if (cString.hasPrefix("#")) { 114 | cString = (cString as NSString).substringFromIndex(1) 115 | } 116 | 117 | if (cString.characters.count != 6) { 118 | return UIColor.grayColor() 119 | } 120 | 121 | let rString = (cString as NSString).substringToIndex(2) 122 | let gString = ((cString as NSString).substringFromIndex(2) as NSString).substringToIndex(2) 123 | let bString = ((cString as NSString).substringFromIndex(4) as NSString).substringToIndex(2) 124 | 125 | var r:CUnsignedInt = 0, g:CUnsignedInt = 0, b:CUnsignedInt = 0; 126 | NSScanner(string: rString).scanHexInt(&r) 127 | NSScanner(string: gString).scanHexInt(&g) 128 | NSScanner(string: bString).scanHexInt(&b) 129 | 130 | return UIColor(red: CGFloat(r) / 255.0, green: CGFloat(g) / 255.0, blue: CGFloat(b) / 255.0, alpha: CGFloat(1)) 131 | } 132 | 133 | /* 134 | * This is image generator. 135 | * The image comes from UIView generated by viewBuilder function. 136 | * params text --> to input the text 137 | * return UIImage 138 | */ 139 | func imageGenerator(text:String) -> UIImage { 140 | UIGraphicsBeginImageContextWithOptions(self.viewBuilder(text, isDynamic: dynamic_gradient).frame.size, false, UIScreen.mainScreen().scale) 141 | self.viewBuilder(text, isDynamic: dynamic_gradient).layer.renderInContext(UIGraphicsGetCurrentContext()!) 142 | let screenshot:UIImage = UIGraphicsGetImageFromCurrentImageContext() 143 | UIGraphicsEndImageContext() 144 | return screenshot 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /DPImageGenerator/GradientView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GradientView.swift 3 | // Gradient View 4 | // 5 | // Created by Sam Soffes on 10/27/09. 6 | // Copyright (c) 2009-2014 Sam Soffes. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | /// Simple view for drawing gradients and borders. 12 | public class GradientView: UIView { 13 | 14 | // MARK: - Types 15 | 16 | /// The mode of the gradient. 17 | public enum Type { 18 | /// A linear gradient. 19 | case Linear 20 | 21 | /// A radial gradient. 22 | case Radial 23 | } 24 | 25 | 26 | /// The direction of the gradient. 27 | public enum Direction { 28 | /// The gradient is vertical. 29 | case Vertical 30 | 31 | /// The gradient is horizontal 32 | case Horizontal 33 | } 34 | 35 | 36 | // MARK: - Properties 37 | 38 | /// An optional array of `UIColor` objects used to draw the gradient. If the value is `nil`, the `backgroundColor` 39 | /// will be drawn instead of a gradient. The default is `nil`. 40 | public var colors: [UIColor]? { 41 | didSet { 42 | updateGradient() 43 | } 44 | } 45 | 46 | /// An array of `UIColor` objects used to draw the dimmed gradient. If the value is `nil`, `colors` will be 47 | /// converted to grayscale. This will use the same `locations` as `colors`. If length of arrays don't match, bad 48 | /// things will happen. You must make sure the number of dimmed colors equals the number of regular colors. 49 | /// 50 | /// The default is `nil`. 51 | public var dimmedColors: [UIColor]? { 52 | didSet { 53 | updateGradient() 54 | } 55 | } 56 | 57 | /// Automatically dim gradient colors when prompted by the system (i.e. when an alert is shown). 58 | /// 59 | /// The default is `true`. 60 | public var automaticallyDims: Bool = true 61 | 62 | /// An optional array of `CGFloat`s defining the location of each gradient stop. 63 | /// 64 | /// The gradient stops are specified as values between `0` and `1`. The values must be monotonically increasing. If 65 | /// `nil`, the stops are spread uniformly across the range. 66 | /// 67 | /// Defaults to `nil`. 68 | public var locations: [CGFloat]? { 69 | didSet { 70 | updateGradient() 71 | } 72 | } 73 | 74 | /// The mode of the gradient. The default is `.Linear`. 75 | public var mode: Type = .Linear { 76 | didSet { 77 | setNeedsDisplay() 78 | } 79 | } 80 | 81 | /// The direction of the gradient. Only valid for the `Mode.Linear` mode. The default is `.Vertical`. 82 | public var direction: Direction = .Vertical { 83 | didSet { 84 | setNeedsDisplay() 85 | } 86 | } 87 | 88 | /// 1px borders will be drawn instead of 1pt borders. The default is `true`. 89 | public var drawsThinBorders: Bool = true { 90 | didSet { 91 | setNeedsDisplay() 92 | } 93 | } 94 | 95 | /// The top border color. The default is `nil`. 96 | public var topBorderColor: UIColor? { 97 | didSet { 98 | setNeedsDisplay() 99 | } 100 | } 101 | 102 | /// The right border color. The default is `nil`. 103 | public var rightBorderColor: UIColor? { 104 | didSet { 105 | setNeedsDisplay() 106 | } 107 | } 108 | 109 | /// The bottom border color. The default is `nil`. 110 | public var bottomBorderColor: UIColor? { 111 | didSet { 112 | setNeedsDisplay() 113 | } 114 | } 115 | 116 | /// The left border color. The default is `nil`. 117 | public var leftBorderColor: UIColor? { 118 | didSet { 119 | setNeedsDisplay() 120 | } 121 | } 122 | 123 | 124 | // MARK: - UIView 125 | 126 | override public func drawRect(rect: CGRect) { 127 | let context = UIGraphicsGetCurrentContext() 128 | let size = bounds.size 129 | 130 | // Gradient 131 | if let gradient = gradient { 132 | let options: CGGradientDrawingOptions = [.DrawsAfterEndLocation] 133 | 134 | if mode == .Linear { 135 | let startPoint = CGPointZero 136 | let endPoint = direction == .Vertical ? CGPoint(x: 0, y: size.height) : CGPoint(x: size.width, y: 0) 137 | CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, options) 138 | } else { 139 | let center = CGPoint(x: bounds.midX, y: bounds.midY) 140 | CGContextDrawRadialGradient(context, gradient, center, 0, center, min(size.width, size.height) / 2, options) 141 | } 142 | } 143 | 144 | let screen: UIScreen = window?.screen ?? UIScreen.mainScreen() 145 | let borderWidth: CGFloat = drawsThinBorders ? 1.0 / screen.scale : 1.0 146 | 147 | // Top border 148 | if let color = topBorderColor { 149 | CGContextSetFillColorWithColor(context, color.CGColor); 150 | CGContextFillRect(context, CGRect(x: 0, y: 0, width: size.width, height: borderWidth)) 151 | } 152 | 153 | let sideY: CGFloat = topBorderColor != nil ? borderWidth : 0 154 | let sideHeight: CGFloat = size.height - sideY - (bottomBorderColor != nil ? borderWidth : 0) 155 | 156 | // Right border 157 | if let color = rightBorderColor { 158 | CGContextSetFillColorWithColor(context, color.CGColor); 159 | CGContextFillRect(context, CGRect(x: size.width - borderWidth, y: sideY, width: borderWidth, height: sideHeight)) 160 | } 161 | 162 | // Bottom border 163 | if let color = bottomBorderColor { 164 | CGContextSetFillColorWithColor(context, color.CGColor); 165 | CGContextFillRect(context, CGRect(x: 0, y: size.height - borderWidth, width: size.width, height: borderWidth)) 166 | } 167 | 168 | // Left border 169 | if let color = leftBorderColor { 170 | CGContextSetFillColorWithColor(context, color.CGColor); 171 | CGContextFillRect(context, CGRect(x: 0, y: sideY, width: borderWidth, height: sideHeight)) 172 | } 173 | } 174 | 175 | override public func tintColorDidChange() { 176 | super.tintColorDidChange() 177 | 178 | if automaticallyDims { 179 | updateGradient() 180 | } 181 | } 182 | 183 | override public func didMoveToWindow() { 184 | super.didMoveToWindow() 185 | contentMode = .Redraw 186 | } 187 | 188 | 189 | // MARK: - Private 190 | 191 | private var gradient: CGGradientRef? 192 | 193 | private func updateGradient() { 194 | gradient = nil 195 | setNeedsDisplay() 196 | 197 | let colors = gradientColors() 198 | if let colors = colors { 199 | let colorSpace = CGColorSpaceCreateDeviceRGB() 200 | let colorSpaceModel = CGColorSpaceGetModel(colorSpace) 201 | 202 | let gradientColors: NSArray = colors.map { (color: UIColor) -> AnyObject! in 203 | let cgColor = color.CGColor 204 | let cgColorSpace = CGColorGetColorSpace(cgColor) 205 | 206 | // The color's color space is RGB, simply add it. 207 | if CGColorSpaceGetModel(cgColorSpace).rawValue == colorSpaceModel.rawValue { 208 | return cgColor as AnyObject! 209 | } 210 | 211 | // Convert to RGB. There may be a more efficient way to do this. 212 | var red: CGFloat = 0 213 | var blue: CGFloat = 0 214 | var green: CGFloat = 0 215 | var alpha: CGFloat = 0 216 | color.getRed(&red, green: &green, blue: &blue, alpha: &alpha) 217 | return UIColor(red: red, green: green, blue: blue, alpha: alpha).CGColor as AnyObject! 218 | } 219 | 220 | // TODO: This is ugly. Surely there is a way to make this more concise. 221 | if let locations = locations { 222 | gradient = CGGradientCreateWithColors(colorSpace, gradientColors, locations) 223 | } else { 224 | gradient = CGGradientCreateWithColors(colorSpace, gradientColors, nil) 225 | } 226 | } 227 | } 228 | 229 | private func gradientColors() -> [UIColor]? { 230 | if tintAdjustmentMode == .Dimmed { 231 | if let dimmedColors = dimmedColors { 232 | return dimmedColors 233 | } 234 | 235 | if automaticallyDims { 236 | if let colors = colors { 237 | return colors.map { 238 | var hue: CGFloat = 0 239 | var brightness: CGFloat = 0 240 | var alpha: CGFloat = 0 241 | 242 | $0.getHue(&hue, saturation: nil, brightness: &brightness, alpha: &alpha) 243 | 244 | return UIColor(hue: hue, saturation: 0, brightness: brightness, alpha: alpha) 245 | } 246 | } 247 | } 248 | } 249 | 250 | return colors 251 | } 252 | } 253 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Dwi Permana Putra (dwi.putra@icloud.com) 2 | 3 | 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | 13 | 14 | The above copyright notice and this permission notice shall be included in 15 | all copies or substantial portions of the Software. 16 | 17 | 18 | 19 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 20 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 21 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 22 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 23 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 24 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 25 | THE SOFTWARE. 26 | 27 | 28 | -------------------------------------------------------------------------------- /LogoGenerator.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | A39F98111BF20CD10003AD89 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = A39F98101BF20CD10003AD89 /* AppDelegate.swift */; }; 11 | A39F98131BF20CD10003AD89 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A39F98121BF20CD10003AD89 /* ViewController.swift */; }; 12 | A39F98161BF20CD10003AD89 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A39F98141BF20CD10003AD89 /* Main.storyboard */; }; 13 | A39F98181BF20CD10003AD89 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = A39F98171BF20CD10003AD89 /* Assets.xcassets */; }; 14 | A39F981B1BF20CD10003AD89 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = A39F98191BF20CD10003AD89 /* LaunchScreen.storyboard */; }; 15 | A3BF155E1BF5685A005D4F9A /* DPImageGenerator.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BF155C1BF5685A005D4F9A /* DPImageGenerator.swift */; }; 16 | A3BF155F1BF5685A005D4F9A /* GradientView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A3BF155D1BF5685A005D4F9A /* GradientView.swift */; }; 17 | /* End PBXBuildFile section */ 18 | 19 | /* Begin PBXFileReference section */ 20 | A39F980D1BF20CD10003AD89 /* LogoGenerator.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = LogoGenerator.app; sourceTree = BUILT_PRODUCTS_DIR; }; 21 | A39F98101BF20CD10003AD89 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 22 | A39F98121BF20CD10003AD89 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 23 | A39F98151BF20CD10003AD89 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 24 | A39F98171BF20CD10003AD89 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 25 | A39F981A1BF20CD10003AD89 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 26 | A39F981C1BF20CD10003AD89 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 27 | A3BF155C1BF5685A005D4F9A /* DPImageGenerator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DPImageGenerator.swift; sourceTree = ""; }; 28 | A3BF155D1BF5685A005D4F9A /* GradientView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GradientView.swift; sourceTree = ""; }; 29 | /* End PBXFileReference section */ 30 | 31 | /* Begin PBXFrameworksBuildPhase section */ 32 | A39F980A1BF20CD00003AD89 /* Frameworks */ = { 33 | isa = PBXFrameworksBuildPhase; 34 | buildActionMask = 2147483647; 35 | files = ( 36 | ); 37 | runOnlyForDeploymentPostprocessing = 0; 38 | }; 39 | /* End PBXFrameworksBuildPhase section */ 40 | 41 | /* Begin PBXGroup section */ 42 | A39F98041BF20CD00003AD89 = { 43 | isa = PBXGroup; 44 | children = ( 45 | A39F980F1BF20CD10003AD89 /* LogoGenerator */, 46 | A39F980E1BF20CD10003AD89 /* Products */, 47 | ); 48 | sourceTree = ""; 49 | }; 50 | A39F980E1BF20CD10003AD89 /* Products */ = { 51 | isa = PBXGroup; 52 | children = ( 53 | A39F980D1BF20CD10003AD89 /* LogoGenerator.app */, 54 | ); 55 | name = Products; 56 | sourceTree = ""; 57 | }; 58 | A39F980F1BF20CD10003AD89 /* LogoGenerator */ = { 59 | isa = PBXGroup; 60 | children = ( 61 | A3BF155B1BF5685A005D4F9A /* DPImageGenerator */, 62 | A39F98101BF20CD10003AD89 /* AppDelegate.swift */, 63 | A39F98121BF20CD10003AD89 /* ViewController.swift */, 64 | A39F98141BF20CD10003AD89 /* Main.storyboard */, 65 | A39F98171BF20CD10003AD89 /* Assets.xcassets */, 66 | A39F98191BF20CD10003AD89 /* LaunchScreen.storyboard */, 67 | A39F981C1BF20CD10003AD89 /* Info.plist */, 68 | ); 69 | path = LogoGenerator; 70 | sourceTree = ""; 71 | }; 72 | A3BF155B1BF5685A005D4F9A /* DPImageGenerator */ = { 73 | isa = PBXGroup; 74 | children = ( 75 | A3BF155C1BF5685A005D4F9A /* DPImageGenerator.swift */, 76 | A3BF155D1BF5685A005D4F9A /* GradientView.swift */, 77 | ); 78 | path = DPImageGenerator; 79 | sourceTree = ""; 80 | }; 81 | /* End PBXGroup section */ 82 | 83 | /* Begin PBXNativeTarget section */ 84 | A39F980C1BF20CD00003AD89 /* LogoGenerator */ = { 85 | isa = PBXNativeTarget; 86 | buildConfigurationList = A39F981F1BF20CD10003AD89 /* Build configuration list for PBXNativeTarget "LogoGenerator" */; 87 | buildPhases = ( 88 | A39F98091BF20CD00003AD89 /* Sources */, 89 | A39F980A1BF20CD00003AD89 /* Frameworks */, 90 | A39F980B1BF20CD00003AD89 /* Resources */, 91 | ); 92 | buildRules = ( 93 | ); 94 | dependencies = ( 95 | ); 96 | name = LogoGenerator; 97 | productName = LogoGenerator; 98 | productReference = A39F980D1BF20CD10003AD89 /* LogoGenerator.app */; 99 | productType = "com.apple.product-type.application"; 100 | }; 101 | /* End PBXNativeTarget section */ 102 | 103 | /* Begin PBXProject section */ 104 | A39F98051BF20CD00003AD89 /* Project object */ = { 105 | isa = PBXProject; 106 | attributes = { 107 | LastSwiftUpdateCheck = 0710; 108 | LastUpgradeCheck = 0710; 109 | ORGANIZATIONNAME = dwipp; 110 | TargetAttributes = { 111 | A39F980C1BF20CD00003AD89 = { 112 | CreatedOnToolsVersion = 7.1; 113 | DevelopmentTeam = 2RL4G4B6A8; 114 | }; 115 | }; 116 | }; 117 | buildConfigurationList = A39F98081BF20CD00003AD89 /* Build configuration list for PBXProject "LogoGenerator" */; 118 | compatibilityVersion = "Xcode 3.2"; 119 | developmentRegion = English; 120 | hasScannedForEncodings = 0; 121 | knownRegions = ( 122 | en, 123 | Base, 124 | ); 125 | mainGroup = A39F98041BF20CD00003AD89; 126 | productRefGroup = A39F980E1BF20CD10003AD89 /* Products */; 127 | projectDirPath = ""; 128 | projectRoot = ""; 129 | targets = ( 130 | A39F980C1BF20CD00003AD89 /* LogoGenerator */, 131 | ); 132 | }; 133 | /* End PBXProject section */ 134 | 135 | /* Begin PBXResourcesBuildPhase section */ 136 | A39F980B1BF20CD00003AD89 /* Resources */ = { 137 | isa = PBXResourcesBuildPhase; 138 | buildActionMask = 2147483647; 139 | files = ( 140 | A39F981B1BF20CD10003AD89 /* LaunchScreen.storyboard in Resources */, 141 | A39F98181BF20CD10003AD89 /* Assets.xcassets in Resources */, 142 | A39F98161BF20CD10003AD89 /* Main.storyboard in Resources */, 143 | ); 144 | runOnlyForDeploymentPostprocessing = 0; 145 | }; 146 | /* End PBXResourcesBuildPhase section */ 147 | 148 | /* Begin PBXSourcesBuildPhase section */ 149 | A39F98091BF20CD00003AD89 /* Sources */ = { 150 | isa = PBXSourcesBuildPhase; 151 | buildActionMask = 2147483647; 152 | files = ( 153 | A3BF155E1BF5685A005D4F9A /* DPImageGenerator.swift in Sources */, 154 | A39F98131BF20CD10003AD89 /* ViewController.swift in Sources */, 155 | A3BF155F1BF5685A005D4F9A /* GradientView.swift in Sources */, 156 | A39F98111BF20CD10003AD89 /* AppDelegate.swift in Sources */, 157 | ); 158 | runOnlyForDeploymentPostprocessing = 0; 159 | }; 160 | /* End PBXSourcesBuildPhase section */ 161 | 162 | /* Begin PBXVariantGroup section */ 163 | A39F98141BF20CD10003AD89 /* Main.storyboard */ = { 164 | isa = PBXVariantGroup; 165 | children = ( 166 | A39F98151BF20CD10003AD89 /* Base */, 167 | ); 168 | name = Main.storyboard; 169 | sourceTree = ""; 170 | }; 171 | A39F98191BF20CD10003AD89 /* LaunchScreen.storyboard */ = { 172 | isa = PBXVariantGroup; 173 | children = ( 174 | A39F981A1BF20CD10003AD89 /* Base */, 175 | ); 176 | name = LaunchScreen.storyboard; 177 | sourceTree = ""; 178 | }; 179 | /* End PBXVariantGroup section */ 180 | 181 | /* Begin XCBuildConfiguration section */ 182 | A39F981D1BF20CD10003AD89 /* Debug */ = { 183 | isa = XCBuildConfiguration; 184 | buildSettings = { 185 | ALWAYS_SEARCH_USER_PATHS = NO; 186 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 187 | CLANG_CXX_LIBRARY = "libc++"; 188 | CLANG_ENABLE_MODULES = YES; 189 | CLANG_ENABLE_OBJC_ARC = YES; 190 | CLANG_WARN_BOOL_CONVERSION = YES; 191 | CLANG_WARN_CONSTANT_CONVERSION = YES; 192 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 193 | CLANG_WARN_EMPTY_BODY = YES; 194 | CLANG_WARN_ENUM_CONVERSION = YES; 195 | CLANG_WARN_INT_CONVERSION = YES; 196 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 197 | CLANG_WARN_UNREACHABLE_CODE = YES; 198 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 199 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 200 | COPY_PHASE_STRIP = NO; 201 | DEBUG_INFORMATION_FORMAT = dwarf; 202 | ENABLE_STRICT_OBJC_MSGSEND = YES; 203 | ENABLE_TESTABILITY = YES; 204 | GCC_C_LANGUAGE_STANDARD = gnu99; 205 | GCC_DYNAMIC_NO_PIC = NO; 206 | GCC_NO_COMMON_BLOCKS = YES; 207 | GCC_OPTIMIZATION_LEVEL = 0; 208 | GCC_PREPROCESSOR_DEFINITIONS = ( 209 | "DEBUG=1", 210 | "$(inherited)", 211 | ); 212 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 213 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 214 | GCC_WARN_UNDECLARED_SELECTOR = YES; 215 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 216 | GCC_WARN_UNUSED_FUNCTION = YES; 217 | GCC_WARN_UNUSED_VARIABLE = YES; 218 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 219 | MTL_ENABLE_DEBUG_INFO = YES; 220 | ONLY_ACTIVE_ARCH = YES; 221 | SDKROOT = iphoneos; 222 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 223 | }; 224 | name = Debug; 225 | }; 226 | A39F981E1BF20CD10003AD89 /* Release */ = { 227 | isa = XCBuildConfiguration; 228 | buildSettings = { 229 | ALWAYS_SEARCH_USER_PATHS = NO; 230 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 231 | CLANG_CXX_LIBRARY = "libc++"; 232 | CLANG_ENABLE_MODULES = YES; 233 | CLANG_ENABLE_OBJC_ARC = YES; 234 | CLANG_WARN_BOOL_CONVERSION = YES; 235 | CLANG_WARN_CONSTANT_CONVERSION = YES; 236 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 237 | CLANG_WARN_EMPTY_BODY = YES; 238 | CLANG_WARN_ENUM_CONVERSION = YES; 239 | CLANG_WARN_INT_CONVERSION = YES; 240 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 241 | CLANG_WARN_UNREACHABLE_CODE = YES; 242 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 243 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 244 | COPY_PHASE_STRIP = NO; 245 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 246 | ENABLE_NS_ASSERTIONS = NO; 247 | ENABLE_STRICT_OBJC_MSGSEND = YES; 248 | GCC_C_LANGUAGE_STANDARD = gnu99; 249 | GCC_NO_COMMON_BLOCKS = YES; 250 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 251 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 252 | GCC_WARN_UNDECLARED_SELECTOR = YES; 253 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 254 | GCC_WARN_UNUSED_FUNCTION = YES; 255 | GCC_WARN_UNUSED_VARIABLE = YES; 256 | IPHONEOS_DEPLOYMENT_TARGET = 9.1; 257 | MTL_ENABLE_DEBUG_INFO = NO; 258 | SDKROOT = iphoneos; 259 | VALIDATE_PRODUCT = YES; 260 | }; 261 | name = Release; 262 | }; 263 | A39F98201BF20CD10003AD89 /* Debug */ = { 264 | isa = XCBuildConfiguration; 265 | buildSettings = { 266 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 267 | CODE_SIGN_IDENTITY = "iPhone Developer"; 268 | INFOPLIST_FILE = LogoGenerator/Info.plist; 269 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 270 | PRODUCT_BUNDLE_IDENTIFIER = com.dwipp.LogoGenerator; 271 | PRODUCT_NAME = "$(TARGET_NAME)"; 272 | }; 273 | name = Debug; 274 | }; 275 | A39F98211BF20CD10003AD89 /* Release */ = { 276 | isa = XCBuildConfiguration; 277 | buildSettings = { 278 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 279 | CODE_SIGN_IDENTITY = "iPhone Developer"; 280 | INFOPLIST_FILE = LogoGenerator/Info.plist; 281 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 282 | PRODUCT_BUNDLE_IDENTIFIER = com.dwipp.LogoGenerator; 283 | PRODUCT_NAME = "$(TARGET_NAME)"; 284 | }; 285 | name = Release; 286 | }; 287 | /* End XCBuildConfiguration section */ 288 | 289 | /* Begin XCConfigurationList section */ 290 | A39F98081BF20CD00003AD89 /* Build configuration list for PBXProject "LogoGenerator" */ = { 291 | isa = XCConfigurationList; 292 | buildConfigurations = ( 293 | A39F981D1BF20CD10003AD89 /* Debug */, 294 | A39F981E1BF20CD10003AD89 /* Release */, 295 | ); 296 | defaultConfigurationIsVisible = 0; 297 | defaultConfigurationName = Release; 298 | }; 299 | A39F981F1BF20CD10003AD89 /* Build configuration list for PBXNativeTarget "LogoGenerator" */ = { 300 | isa = XCConfigurationList; 301 | buildConfigurations = ( 302 | A39F98201BF20CD10003AD89 /* Debug */, 303 | A39F98211BF20CD10003AD89 /* Release */, 304 | ); 305 | defaultConfigurationIsVisible = 0; 306 | defaultConfigurationName = Release; 307 | }; 308 | /* End XCConfigurationList section */ 309 | }; 310 | rootObject = A39F98051BF20CD00003AD89 /* Project object */; 311 | } 312 | -------------------------------------------------------------------------------- /LogoGenerator.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /LogoGenerator.xcodeproj/project.xcworkspace/xcuserdata/dwipp.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPImageGenerator/b9076f7fd53c39bfeab04772c3798ba9630920a8/LogoGenerator.xcodeproj/project.xcworkspace/xcuserdata/dwipp.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /LogoGenerator.xcodeproj/project.xcworkspace/xcuserdata/putra27kenji.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/dwipp/DPImageGenerator/b9076f7fd53c39bfeab04772c3798ba9630920a8/LogoGenerator.xcodeproj/project.xcworkspace/xcuserdata/putra27kenji.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /LogoGenerator.xcodeproj/xcuserdata/dwipp.xcuserdatad/xcschemes/LogoGenerator.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /LogoGenerator.xcodeproj/xcuserdata/dwipp.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | LogoGenerator.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | A39F980C1BF20CD00003AD89 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LogoGenerator.xcodeproj/xcuserdata/putra27kenji.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /LogoGenerator.xcodeproj/xcuserdata/putra27kenji.xcuserdatad/xcschemes/LogoGenerator.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 32 | 33 | 39 | 40 | 41 | 42 | 43 | 44 | 54 | 56 | 62 | 63 | 64 | 65 | 66 | 67 | 73 | 75 | 81 | 82 | 83 | 84 | 86 | 87 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /LogoGenerator.xcodeproj/xcuserdata/putra27kenji.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | LogoGenerator.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | A39F980C1BF20CD00003AD89 16 | 17 | primary 18 | 19 | 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /LogoGenerator/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // LogoGenerator 4 | // 5 | // Created by Dwi Putra on 11/10/15. 6 | // Copyright © 2015 dwipp. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | @UIApplicationMain 12 | class AppDelegate: UIResponder, UIApplicationDelegate { 13 | 14 | var window: UIWindow? 15 | 16 | 17 | func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool { 18 | // Override point for customization after application launch. 19 | return true 20 | } 21 | 22 | func applicationWillResignActive(application: UIApplication) { 23 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 24 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 25 | } 26 | 27 | func applicationDidEnterBackground(application: UIApplication) { 28 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 29 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 30 | } 31 | 32 | func applicationWillEnterForeground(application: UIApplication) { 33 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 34 | } 35 | 36 | func applicationDidBecomeActive(application: UIApplication) { 37 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 38 | } 39 | 40 | func applicationWillTerminate(application: UIApplication) { 41 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 42 | } 43 | 44 | 45 | } 46 | 47 | -------------------------------------------------------------------------------- /LogoGenerator/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /LogoGenerator/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /LogoGenerator/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /LogoGenerator/DPImageGenerator/DPImageGenerator.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DPImageGenerator.swift 3 | // LogoGenerator 4 | // 5 | // Created by Dwi Putra on 11/10/15. 6 | // Copyright © 2015 dwipp. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | // Enum for selecting max character allowed inside of image 12 | enum maxCharacter { 13 | case one 14 | case two 15 | } 16 | 17 | class DPImageGenerator: NSObject { 18 | var image_frame:CGRect? 19 | var text_color:UIColor? 20 | var text_font:UIFont? 21 | var max_char:maxCharacter = .two 22 | var dynamic_gradient:Bool = true 23 | 24 | 25 | /* 26 | * This is a view buider. 27 | * Holding selected random gradient color and first character of every words 28 | * params text --> to input the text 29 | * params isDynamic --> an option for dynamic gradient 30 | * return UIView 31 | */ 32 | private func viewBuilder(text:String, isDynamic:Bool) -> UIView { 33 | let color1:[String] = ["EF4DB6", "52EDC7", "55EFCB", "0D77EF", "5AD427", "87FC70", "FF9500", "C86EDF", "55EFCB"] 34 | let color2:[String] = ["C643FC", "5AC8FB", "5BCAFF", "81F3FD", "A4E786", "0BD318", "FF5E3A", "E4B7F0", "5BCAFF"] 35 | 36 | let x:Int? 37 | if isDynamic { 38 | x = Int(arc4random_uniform(UInt32(color1.count))) 39 | }else { 40 | srandom(UInt32(text.characters.count)) 41 | x = Int(random()%color1.count) 42 | } 43 | 44 | let defaultView = UIView(frame: image_frame!) 45 | let gradient: GradientView = GradientView() 46 | 47 | let colors:[UIColor] = [self.colorWithHexString(color1[x!]), self.colorWithHexString(color2[x!])] 48 | 49 | gradient.frame = defaultView.bounds 50 | gradient.colors = colors 51 | gradient.locations = [0.0 , 1.0] 52 | defaultView.addSubview(gradient) 53 | 54 | let width_value = ((image_frame?.width)! - 20) 55 | let height_value = ((image_frame?.height)! / 2) 56 | let x_value = ((image_frame?.width)! - width_value)/2 57 | let y_value = ((image_frame?.height)! - height_value)/2 58 | 59 | let initialName:UILabel = UILabel(frame: CGRectMake(x_value, y_value, width_value, height_value)) 60 | var first_letter:String? 61 | let first_character:NSMutableString = NSMutableString() 62 | let words:[NSString] = text.componentsSeparatedByCharactersInSet(NSCharacterSet.whitespaceCharacterSet()) 63 | 64 | var count=0 65 | for word in words { 66 | if word.length > 0 && count < self.getMaxChar(max_char) { 67 | first_letter = word.substringToIndex(1) 68 | first_character.appendString((first_letter?.uppercaseString)!) 69 | count++ 70 | } 71 | } 72 | initialName.text = first_character as String 73 | initialName.textColor = self.getTextColor(self.text_color) 74 | initialName.textAlignment = NSTextAlignment.Center 75 | initialName.font = self.getTextFont(self.text_font) 76 | defaultView.addSubview(initialName) 77 | return defaultView 78 | } 79 | 80 | private func getMaxChar(max:maxCharacter) -> Int { 81 | switch max{ 82 | case .one : 83 | return 1 84 | case .two : 85 | return 2 86 | } 87 | } 88 | 89 | private func getTextColor(color:UIColor?) -> UIColor { 90 | if color != nil { 91 | return color! 92 | }else { 93 | return UIColor.whiteColor() 94 | } 95 | } 96 | 97 | private func getTextFont(font:UIFont?) -> UIFont { 98 | if font != nil { 99 | return font! 100 | }else { 101 | return UIFont.systemFontOfSize(70) 102 | } 103 | } 104 | 105 | /* 106 | * This method will convert hex color to be RGB color. 107 | * params hex --> hex color in string value 108 | * return UIColor 109 | */ 110 | private func colorWithHexString (hex:String) -> UIColor { 111 | var cString:String = hex.stringByTrimmingCharactersInSet(NSCharacterSet.whitespaceAndNewlineCharacterSet()).uppercaseString 112 | 113 | if (cString.hasPrefix("#")) { 114 | cString = (cString as NSString).substringFromIndex(1) 115 | } 116 | 117 | if (cString.characters.count != 6) { 118 | return UIColor.grayColor() 119 | } 120 | 121 | let rString = (cString as NSString).substringToIndex(2) 122 | let gString = ((cString as NSString).substringFromIndex(2) as NSString).substringToIndex(2) 123 | let bString = ((cString as NSString).substringFromIndex(4) as NSString).substringToIndex(2) 124 | 125 | var r:CUnsignedInt = 0, g:CUnsignedInt = 0, b:CUnsignedInt = 0; 126 | NSScanner(string: rString).scanHexInt(&r) 127 | NSScanner(string: gString).scanHexInt(&g) 128 | NSScanner(string: bString).scanHexInt(&b) 129 | 130 | return UIColor(red: CGFloat(r) / 255.0, green: CGFloat(g) / 255.0, blue: CGFloat(b) / 255.0, alpha: CGFloat(1)) 131 | } 132 | 133 | /* 134 | * This is image generator. 135 | * The image comes from UIView generated by viewBuilder function. 136 | * params text --> to input the text 137 | * return UIImage 138 | */ 139 | func imageGenerator(text:String) -> UIImage { 140 | UIGraphicsBeginImageContextWithOptions(self.viewBuilder(text, isDynamic: dynamic_gradient).frame.size, false, UIScreen.mainScreen().scale) 141 | self.viewBuilder(text, isDynamic: dynamic_gradient).layer.renderInContext(UIGraphicsGetCurrentContext()!) 142 | let screenshot:UIImage = UIGraphicsGetImageFromCurrentImageContext() 143 | UIGraphicsEndImageContext() 144 | return screenshot 145 | } 146 | } 147 | -------------------------------------------------------------------------------- /LogoGenerator/DPImageGenerator/GradientView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // GradientView.swift 3 | // Gradient View 4 | // 5 | // Created by Sam Soffes on 10/27/09. 6 | // Copyright (c) 2009-2014 Sam Soffes. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | /// Simple view for drawing gradients and borders. 12 | public class GradientView: UIView { 13 | 14 | // MARK: - Types 15 | 16 | /// The mode of the gradient. 17 | public enum Type { 18 | /// A linear gradient. 19 | case Linear 20 | 21 | /// A radial gradient. 22 | case Radial 23 | } 24 | 25 | 26 | /// The direction of the gradient. 27 | public enum Direction { 28 | /// The gradient is vertical. 29 | case Vertical 30 | 31 | /// The gradient is horizontal 32 | case Horizontal 33 | } 34 | 35 | 36 | // MARK: - Properties 37 | 38 | /// An optional array of `UIColor` objects used to draw the gradient. If the value is `nil`, the `backgroundColor` 39 | /// will be drawn instead of a gradient. The default is `nil`. 40 | public var colors: [UIColor]? { 41 | didSet { 42 | updateGradient() 43 | } 44 | } 45 | 46 | /// An array of `UIColor` objects used to draw the dimmed gradient. If the value is `nil`, `colors` will be 47 | /// converted to grayscale. This will use the same `locations` as `colors`. If length of arrays don't match, bad 48 | /// things will happen. You must make sure the number of dimmed colors equals the number of regular colors. 49 | /// 50 | /// The default is `nil`. 51 | public var dimmedColors: [UIColor]? { 52 | didSet { 53 | updateGradient() 54 | } 55 | } 56 | 57 | /// Automatically dim gradient colors when prompted by the system (i.e. when an alert is shown). 58 | /// 59 | /// The default is `true`. 60 | public var automaticallyDims: Bool = true 61 | 62 | /// An optional array of `CGFloat`s defining the location of each gradient stop. 63 | /// 64 | /// The gradient stops are specified as values between `0` and `1`. The values must be monotonically increasing. If 65 | /// `nil`, the stops are spread uniformly across the range. 66 | /// 67 | /// Defaults to `nil`. 68 | public var locations: [CGFloat]? { 69 | didSet { 70 | updateGradient() 71 | } 72 | } 73 | 74 | /// The mode of the gradient. The default is `.Linear`. 75 | public var mode: Type = .Linear { 76 | didSet { 77 | setNeedsDisplay() 78 | } 79 | } 80 | 81 | /// The direction of the gradient. Only valid for the `Mode.Linear` mode. The default is `.Vertical`. 82 | public var direction: Direction = .Vertical { 83 | didSet { 84 | setNeedsDisplay() 85 | } 86 | } 87 | 88 | /// 1px borders will be drawn instead of 1pt borders. The default is `true`. 89 | public var drawsThinBorders: Bool = true { 90 | didSet { 91 | setNeedsDisplay() 92 | } 93 | } 94 | 95 | /// The top border color. The default is `nil`. 96 | public var topBorderColor: UIColor? { 97 | didSet { 98 | setNeedsDisplay() 99 | } 100 | } 101 | 102 | /// The right border color. The default is `nil`. 103 | public var rightBorderColor: UIColor? { 104 | didSet { 105 | setNeedsDisplay() 106 | } 107 | } 108 | 109 | /// The bottom border color. The default is `nil`. 110 | public var bottomBorderColor: UIColor? { 111 | didSet { 112 | setNeedsDisplay() 113 | } 114 | } 115 | 116 | /// The left border color. The default is `nil`. 117 | public var leftBorderColor: UIColor? { 118 | didSet { 119 | setNeedsDisplay() 120 | } 121 | } 122 | 123 | 124 | // MARK: - UIView 125 | 126 | override public func drawRect(rect: CGRect) { 127 | let context = UIGraphicsGetCurrentContext() 128 | let size = bounds.size 129 | 130 | // Gradient 131 | if let gradient = gradient { 132 | let options: CGGradientDrawingOptions = [.DrawsAfterEndLocation] 133 | 134 | if mode == .Linear { 135 | let startPoint = CGPointZero 136 | let endPoint = direction == .Vertical ? CGPoint(x: 0, y: size.height) : CGPoint(x: size.width, y: 0) 137 | CGContextDrawLinearGradient(context, gradient, startPoint, endPoint, options) 138 | } else { 139 | let center = CGPoint(x: bounds.midX, y: bounds.midY) 140 | CGContextDrawRadialGradient(context, gradient, center, 0, center, min(size.width, size.height) / 2, options) 141 | } 142 | } 143 | 144 | let screen: UIScreen = window?.screen ?? UIScreen.mainScreen() 145 | let borderWidth: CGFloat = drawsThinBorders ? 1.0 / screen.scale : 1.0 146 | 147 | // Top border 148 | if let color = topBorderColor { 149 | CGContextSetFillColorWithColor(context, color.CGColor); 150 | CGContextFillRect(context, CGRect(x: 0, y: 0, width: size.width, height: borderWidth)) 151 | } 152 | 153 | let sideY: CGFloat = topBorderColor != nil ? borderWidth : 0 154 | let sideHeight: CGFloat = size.height - sideY - (bottomBorderColor != nil ? borderWidth : 0) 155 | 156 | // Right border 157 | if let color = rightBorderColor { 158 | CGContextSetFillColorWithColor(context, color.CGColor); 159 | CGContextFillRect(context, CGRect(x: size.width - borderWidth, y: sideY, width: borderWidth, height: sideHeight)) 160 | } 161 | 162 | // Bottom border 163 | if let color = bottomBorderColor { 164 | CGContextSetFillColorWithColor(context, color.CGColor); 165 | CGContextFillRect(context, CGRect(x: 0, y: size.height - borderWidth, width: size.width, height: borderWidth)) 166 | } 167 | 168 | // Left border 169 | if let color = leftBorderColor { 170 | CGContextSetFillColorWithColor(context, color.CGColor); 171 | CGContextFillRect(context, CGRect(x: 0, y: sideY, width: borderWidth, height: sideHeight)) 172 | } 173 | } 174 | 175 | override public func tintColorDidChange() { 176 | super.tintColorDidChange() 177 | 178 | if automaticallyDims { 179 | updateGradient() 180 | } 181 | } 182 | 183 | override public func didMoveToWindow() { 184 | super.didMoveToWindow() 185 | contentMode = .Redraw 186 | } 187 | 188 | 189 | // MARK: - Private 190 | 191 | private var gradient: CGGradientRef? 192 | 193 | private func updateGradient() { 194 | gradient = nil 195 | setNeedsDisplay() 196 | 197 | let colors = gradientColors() 198 | if let colors = colors { 199 | let colorSpace = CGColorSpaceCreateDeviceRGB() 200 | let colorSpaceModel = CGColorSpaceGetModel(colorSpace) 201 | 202 | let gradientColors: NSArray = colors.map { (color: UIColor) -> AnyObject! in 203 | let cgColor = color.CGColor 204 | let cgColorSpace = CGColorGetColorSpace(cgColor) 205 | 206 | // The color's color space is RGB, simply add it. 207 | if CGColorSpaceGetModel(cgColorSpace).rawValue == colorSpaceModel.rawValue { 208 | return cgColor as AnyObject! 209 | } 210 | 211 | // Convert to RGB. There may be a more efficient way to do this. 212 | var red: CGFloat = 0 213 | var blue: CGFloat = 0 214 | var green: CGFloat = 0 215 | var alpha: CGFloat = 0 216 | color.getRed(&red, green: &green, blue: &blue, alpha: &alpha) 217 | return UIColor(red: red, green: green, blue: blue, alpha: alpha).CGColor as AnyObject! 218 | } 219 | 220 | // TODO: This is ugly. Surely there is a way to make this more concise. 221 | if let locations = locations { 222 | gradient = CGGradientCreateWithColors(colorSpace, gradientColors, locations) 223 | } else { 224 | gradient = CGGradientCreateWithColors(colorSpace, gradientColors, nil) 225 | } 226 | } 227 | } 228 | 229 | private func gradientColors() -> [UIColor]? { 230 | if tintAdjustmentMode == .Dimmed { 231 | if let dimmedColors = dimmedColors { 232 | return dimmedColors 233 | } 234 | 235 | if automaticallyDims { 236 | if let colors = colors { 237 | return colors.map { 238 | var hue: CGFloat = 0 239 | var brightness: CGFloat = 0 240 | var alpha: CGFloat = 0 241 | 242 | $0.getHue(&hue, saturation: nil, brightness: &brightness, alpha: &alpha) 243 | 244 | return UIColor(hue: hue, saturation: 0, brightness: brightness, alpha: alpha) 245 | } 246 | } 247 | } 248 | } 249 | 250 | return colors 251 | } 252 | } 253 | -------------------------------------------------------------------------------- /LogoGenerator/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 0.1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | LSRequiresIPhoneOS 24 | 25 | UILaunchStoryboardName 26 | LaunchScreen 27 | UIMainStoryboardFile 28 | Main 29 | UIRequiredDeviceCapabilities 30 | 31 | armv7 32 | 33 | UISupportedInterfaceOrientations 34 | 35 | UIInterfaceOrientationPortrait 36 | 37 | 38 | 39 | -------------------------------------------------------------------------------- /LogoGenerator/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // LogoGenerator 4 | // 5 | // Created by Dwi Putra on 11/10/15. 6 | // Copyright © 2015 dwipp. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | class ViewController: UIViewController { 12 | @IBOutlet var txt_field: UITextField! 13 | @IBOutlet var img_image: UIImageView! 14 | 15 | let imageGen:DPImageGenerator = DPImageGenerator() 16 | 17 | 18 | override func viewDidLoad() { 19 | super.viewDidLoad() 20 | img_image.layer.cornerRadius = 15 21 | imageGen.image_frame = img_image.frame 22 | imageGen.text_font = UIFont(name: "HelveticaNeue", size: 80) 23 | imageGen.text_color = UIColor.whiteColor() 24 | imageGen.max_char = maxCharacter.two 25 | imageGen.dynamic_gradient = true 26 | } 27 | 28 | override func didReceiveMemoryWarning() { 29 | super.didReceiveMemoryWarning() 30 | // Dispose of any resources that can be recreated. 31 | } 32 | 33 | @IBAction func action_generate(sender: AnyObject) { 34 | self.view.endEditing(true) 35 | if txt_field.text != "" { 36 | img_image.image = imageGen.imageGenerator(txt_field.text!) 37 | } 38 | } 39 | } 40 | 41 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DPImageGenerator 2 | 3 | Easily to generate image for default photo profile, etc. 4 | DPImageGenerator is tested on iOS 9. 5 | This awesome library is wrote on swift 2.1 6 | 7 | 8 | ## Usage 9 | 10 | ``` swift 11 | // Initialize an image generator. It's required. 12 | let imageGen:DPImageGenerator = DPImageGenerator() 13 | 14 | // Set frame using UIImage frame. It's required. 15 | imageGen.image_frame = img_image.frame 16 | 17 | // Set font for text inside image. The default is system font with font size 70. 18 | imageGen.text_font = UIFont(name: "HelveticaNeue", size: 80) 19 | 20 | // Set text color. The default is white 21 | imageGen.text_color = UIColor.whiteColor() 22 | 23 | // Set maximum character allowed inside image. 24 | // The option are two and one. And two as default value. 25 | imageGen.max_char = maxCharacter.two 26 | 27 | // Set text. It is required. 28 | imageView.image = imageGen.imageGenerator("Dwi Putra") 29 | 30 | /* Set dynamic gradient. 31 | Gradient color will be changed for every generate (true). 32 | Gradient color will be changed when it gets different char lenght (false). 33 | The default is true 34 | */ 35 | imageGen.dynamic_gradient = false 36 | ``` 37 | 38 | ## Sample 39 | 40 | ![Screenshot](http://s29.postimg.org/pnglt4snb/i_OSputra27kenji11132015075025.png) 41 | ![Screenshot](http://s2.postimg.org/nuxvuceh5/i_OSputra27kenji11132015075047.png) 42 | ![gif](http://i.giphy.com/3o7rc0XWQikS45IALu.gif) 43 | 44 | [This is the video sample](http://www.youtube.com/watch?v=hxBvk4Esj08) 45 | 46 | ## Installation 47 | 48 | Manual installation. Just copy DPImageGenerator folder to your project. 49 | Will be available on cocoapods soon. 50 | 51 | ## Thanks To 52 | 53 | soffes --> https://github.com/soffes/GradientView 54 | 55 | ## License 56 | 57 | DPImageGenerator is released under the MIT license. See LICENSE for details. 58 | --------------------------------------------------------------------------------