Skip to content

Commit 64d6e2b

Browse files
authored
Merge pull request #84 from johnsonea/add-quality
add an image quality switch
2 parents c102a12 + 6e326bf commit 64d6e2b

4 files changed

Lines changed: 20 additions & 3 deletions

File tree

‎README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ Command options are:
7070
-o output file name (default is 'output.heic')
7171
-i input .json file with wallpaper description
7272
-e input .heic file to extract metadata
73+
-q quality of the output images (default is 1.0)
7374
```
7475

7576
That's all. Now you can build your own dynamic wallpapers.

‎Sources/Wallpapper/OptionType.swift‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ enum OptionType: String {
1212
case input = "-i"
1313
case output = "-o"
1414
case extract = "-e"
15+
case quality = "-q"
1516
case unknown
1617

1718
init(value: String) {
@@ -21,6 +22,7 @@ enum OptionType: String {
2122
case "-i": self = .input
2223
case "-o": self = .output
2324
case "-e": self = .extract
25+
case "-q": self = .quality
2426
default: self = .unknown
2527
}
2628
}

‎Sources/Wallpapper/Program.swift‎

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class Program {
1313
var inputFileName = ""
1414
var outputFileName: String? = nil
1515
var shouldExtract = false
16+
var quality: Double = 1.0
1617

1718
func run() -> Bool {
1819

@@ -88,7 +89,7 @@ class Program {
8889
let baseURL = fileURL.deletingLastPathComponent()
8990
let wallpaperGenerator = WallpaperGenerator()
9091
let fileName = self.outputFileName ?? "output.heic"
91-
try wallpaperGenerator.generate(pictureInfos: pictureInfos, baseURL: baseURL, outputFileName: fileName);
92+
try wallpaperGenerator.generate(pictureInfos: pictureInfos, baseURL: baseURL, outputFileName: fileName, quality: self.quality);
9293
} catch (let error as WallpapperError) {
9394
self.consoleIO.writeMessage("Unexpected error occurs: \(error.message)", to: .error)
9495
return false
@@ -162,6 +163,18 @@ class Program {
162163
optionIndex = inputNameOptionIndex
163164

164165
self.shouldExtract = true
166+
case .quality:
167+
let inputNameOptionIndex = optionIndex + 1
168+
if inputNameOptionIndex < CommandLine.arguments.count {
169+
if let value = Double(CommandLine.arguments[inputNameOptionIndex]) {
170+
quality = value
171+
} else {
172+
self.consoleIO.writeMessage("invalid quality number", to: .error)
173+
return (true, false)
174+
}
175+
}
176+
177+
optionIndex = inputNameOptionIndex
165178
default:
166179
break;
167180
}
@@ -192,5 +205,6 @@ class Program {
192205
self.consoleIO.writeMessage(" -o\t\t\toutput file name (default is 'output.heic')")
193206
self.consoleIO.writeMessage(" -i\t\t\tinput .json file with wallpaper description")
194207
self.consoleIO.writeMessage(" -e\t\t\tinput .heic file to extract metadata")
208+
self.consoleIO.writeMessage(" -q\t\t\tquality (default = 1.0)")
195209
}
196210
}

‎Sources/WallpapperLib/DynamicWallpaperGenerator/WallpaperGenerator.swift‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ public class WallpaperGenerator {
1313
public init() {
1414
}
1515

16-
public func generate(pictureInfos: [PictureInfo], baseURL: URL, outputFileName: String) throws {
16+
public func generate(pictureInfos: [PictureInfo], baseURL: URL, outputFileName: String, quality: Double) throws {
1717
let consoleIO = ConsoleIO()
18-
let options = [kCGImageDestinationLossyCompressionQuality: 1.0]
18+
let options = [kCGImageDestinationLossyCompressionQuality: quality]
1919

2020
if #available(OSX 10.13, *) {
2121

0 commit comments

Comments
 (0)