Permalink
Browse files

fixed alpha channel issue

  • Loading branch information...
1 parent 73727fa commit 875d8440d67efe8d335c52e65918dcfde201cea6 @leogdion leogdion committed Dec 21, 2016
View
@@ -32,6 +32,7 @@ Temporary Items
## Build generated
build/
DerivedData/
+Products/
## Various settings
# Xcode
View
@@ -89,21 +89,23 @@ or
```json
{
"set" : "Assets.xcassets/iOS AppIcon.appiconset",
-"source" : "geometry.svg"
+"source" : "geometry.svg",
+"background" : "#FFFFFFFF",
+"remove-alpha" : true
}
```
-#### Set
+#### Set `set`
<img src="https://raw.githubusercontent.com/brightdigit/speculid/master/assets/images/SetExample.png" width="320" height="240" alt="Image Set Examples from Xcode">
A set is an image set or app icon set used by Xcode. That path specified in the json could be relative to the `.spcld` file.
-#### Source
+#### Source `source`
The image source file which could be a SVG or any bitmap image type compatible with [imagemagick](http://www.imagemagick.org).
-#### Geometry *optional*
+#### Geometry *optional* `geometry`
The destination geometry of image if needed (i.e. image set). It must be in the format of:
@@ -112,6 +114,14 @@ The destination geometry of image if needed (i.e. image set). It must be in the
You can only specify the height or the width. The other dimension is automatically calculated based on the aspect ration of the image.
+#### Background *optional* `background`
+
+As a requirement, **App Icons are required to exclude any alpha channels**. In order to remove a transparency from a source png or svg file, you can specify to remove the alpha channel and add a background color. The background color can be set with a string in a standard rgb, rgba, or hex code format (#RRGGBB or #AARRGGBB). If no alpha is specified an alpha of 1.0 is assumed.
+
+#### Remove Alpha *optional* `remove-alpha`
+
+To specifically remove the alpha channel, a true boolean value must be specified. This will remove the alpha channel from the file. Make sure to specify an opaque background color when removing the alpha channel.
+
### Application Configuration
If you install **Speculid** using the standard homebrew path, it should be able to find the nessacary applications needed. However if you need to set the path to the dependency applications, create a `json` file in your home directory `/Users/username/` named `speculid.json`. Then specify the paths to the application dependencies:
@@ -1,5 +1,6 @@
{
"set" : "Assets.xcassets/iOS AppIcon.appiconset",
"source" : "geometry.svg",
-"background" : "#FFFFFF"
+"background" : "#FFFFFF",
+"remove-alpha" : true
}
@@ -1,5 +1,6 @@
{
"set" : "Assets.xcassets/macOS AppIcon.appiconset",
"source" : "geometry.svg",
-"background" : "#FFFFFF"
+"background" : "#FFFFFF",
+"remove-alpha" : true
}
View
@@ -1 +1 @@
-d8d65120ef77d026a965b4515fd8aa53681b7e45e9580add63e832367d0cd79e6b3e01b1415d34fbbbd9e68ac8b281ef389914ed4c86250b50e4aceb7fccbb58 -
+ead6d7c5d3b8e2d0a78338ab624b9ad4a146f15f62927fad10fd141df91be663a7ebbcb5024925ecb97b6bd1a3b0c559dba6c33176a331c914ca07011e688c97 -
@@ -10,6 +10,9 @@ import Foundation
public struct SVGImageConversionBuilder : ImageConversionBuilderProtocol {
public func conversion(forImage imageSpecification: ImageSpecificationProtocol, withSpecifications specifications: SpeculidSpecificationsProtocol, andConfiguration configuration: SpeculidConfigurationProtocol) -> ConversionResult? {
+
+ let removeAlphaProcess: Process?
+
guard let scale = imageSpecification.scale else {
return nil
}
@@ -22,7 +25,24 @@ public struct SVGImageConversionBuilder : ImageConversionBuilderProtocol {
return .Error(MissingRequiredInstallationError(name: "inkscape"))
}
- var arguments : [String] = ["--without-gui","--export-png", specifications.contentsDirectoryURL.appendingPathComponent(specifications.destination(forImage: imageSpecification)).path]
+ let temporaryUrl = URL(fileURLWithPath: NSTemporaryDirectory(), isDirectory: true).appendingPathComponent(UUID().uuidString)
+
+ let inkScapeDestinationPath = specifications.removeAlpha ? temporaryUrl.path : specifications.contentsDirectoryURL.appendingPathComponent(specifications.destination(forImage: imageSpecification)).path
+
+ if specifications.removeAlpha {
+ if let convertURL = configuration.convertURL {
+ let process = Process()
+ process.launchPath = convertURL.path
+ process.arguments = [inkScapeDestinationPath,"-alpha","remove","-alpha","off",specifications.contentsDirectoryURL.appendingPathComponent(specifications.destination(forImage: imageSpecification)).path]
+ removeAlphaProcess = process
+ } else {
+ return .Error(MissingRequiredInstallationError(name: "imagemagick"))
+ }
+ } else {
+ removeAlphaProcess = nil
+ }
+
+ var arguments : [String] = ["--without-gui","--export-png", inkScapeDestinationPath]
if let background = specifications.background {
@@ -50,10 +70,18 @@ public struct SVGImageConversionBuilder : ImageConversionBuilderProtocol {
arguments.append(contentsOf: ["-d", "\(90*scale)" ,specifications.sourceImageURL.absoluteURL.path])
}
+ //
+
+
let process = Process()
process.launchPath = inkscapeURL.path
process.arguments = arguments
print(arguments.joined(separator: " "))
- return .Task(ProcessImageConversionTask(process: process))
+
+ if let removeAlphaProcess = removeAlphaProcess {
+ return .Task(ProcessImageConversionTask(process: SerialProcess(processes: [process, removeAlphaProcess]) ))
+ } else {
+ return .Task(ProcessImageConversionTask(process: process))
+ }
}
}
@@ -11,15 +11,18 @@ public struct SpeculidSpecifications : SpeculidSpecificationsProtocol {
public let sourceImageURL : URL
public let geometry: Geometry?
public let background: NSColor?
+ public let removeAlpha: Bool
public init (contentsDirectoryURL : URL,
sourceImageURL : URL,
geometry: Geometry? = nil,
- background: NSColor? = nil) {
+ background: NSColor? = nil,
+ removeAlpha: Bool = false) {
self.contentsDirectoryURL = contentsDirectoryURL
self.geometry = geometry
self.sourceImageURL = sourceImageURL
self.background = background
+ self.removeAlpha = removeAlpha
}
public init?(url: URL) {
@@ -34,21 +37,21 @@ public struct SpeculidSpecifications : SpeculidSpecificationsProtocol {
return nil
}
- guard let dictionary = json as? [String : String] else {
+ guard let dictionary = json as? [String : Any] else {
return nil
}
- guard let setRelativePath = dictionary["set"], let sourceRelativePath = dictionary["source"] else {
+ guard let setRelativePath = dictionary["set"] as? String, let sourceRelativePath = dictionary["source"] as? String else {
return nil
}
- if let backgroundString = dictionary["background"] {
+ if let backgroundString = dictionary["background"] as? String {
background = NSColor(backgroundString)
} else {
background = nil
}
- if let geometryString = dictionary["geometry"] {
+ if let geometryString = dictionary["geometry"] as? String {
geometry = Geometry(string: geometryString)
} else {
geometry = nil
@@ -62,6 +65,7 @@ public struct SpeculidSpecifications : SpeculidSpecificationsProtocol {
self.sourceImageURL = sourceImageURL
self.geometry = geometry
self.background = background
+ self.removeAlpha = dictionary["remove-alpha"] as? Bool ?? false
}
}
@@ -12,6 +12,41 @@ public protocol ProcessProtocol {
func launch (_ callback: @escaping (Error?) -> Void)
}
+public class SerialProcessCollection {
+ public let processes : [ProcessProtocol]
+ public var index = -1
+ public let callback: (Error?) -> Void
+
+ public init (processes: [ProcessProtocol], callback: @escaping (Error?) -> Void) {
+ self.processes = processes
+ self.callback = callback
+ }
+
+ public func start () {
+ next(error: nil)
+ }
+
+ public func next (error: Error?) {
+ self.index = self.index + 1
+ if let error = error {
+ self.callback(error)
+ } else if self.index < self.processes.count {
+ self.processes[self.index].launch(self.next)
+ } else {
+ self.callback(nil)
+ }
+ }
+}
+
+public struct SerialProcess : ProcessProtocol {
+ public let processes : [ProcessProtocol]
+
+ public func launch(_ callback: @escaping (Error?) -> Void) {
+ let collection = SerialProcessCollection(processes: self.processes, callback: callback)
+ collection.start()
+ }
+}
+
extension Process : ProcessProtocol {
public func launch (_ callback: @escaping (Error?) -> Void) {
let pipe = Pipe()
@@ -11,4 +11,5 @@ public protocol SpeculidSpecificationsProtocol {
var sourceImageURL : URL { get }
var geometry : Geometry? { get }
var background : NSColor? { get }
+ var removeAlpha : Bool { get }
}
View
@@ -3,16 +3,16 @@
let VCS_TYPE = "git"
let VCS_BASENAME = "speculid"
let VCS_UUID: String? = "b6fd659a7d2088d5420f962a307b1f7f7e5d0604"
-let VCS_NUM: Int = 454
-let VCS_DATE = "2016-12-09T17:29:08Z"
-let VCS_BRANCH: String = "develop"
+let VCS_NUM: Int = 455
+let VCS_DATE = "2016-12-21T13:43:07Z"
+let VCS_BRANCH: String = "feature/remove-alpha-channel"
let VCS_TAG: String? = "1.0.1"
-let VCS_TICK: Int? = 4
-let VCS_EXTRA: String? = "54"
+let VCS_TICK: Int? = 5
+let VCS_EXTRA: String? = "63"
-let VCS_ACTION_STAMP: String? = "2016-12-09T17:29:08Z!leogdion@brightdigit.com"
-let VCS_FULL_HASH: String = "6e96366d0ab6b4da40a3280f424c2bed10a42ecd"
-let VCS_SHORT_HASH: String = "6e96366"
+let VCS_ACTION_STAMP: String? = "2016-12-21T13:43:07Z!leogdion@brightdigit.com"
+let VCS_FULL_HASH: String = "73727fa5e85a42d94b4de3fd18744fecf6510722"
+let VCS_SHORT_HASH: String = "73727fa"
let VCS_WC_MODIFIED: Bool = true

0 comments on commit 875d844

Please sign in to comment.