ios_icon_generator 0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f852400e4c7991cb98356bac374aaf2b94c47af
4
+ data.tar.gz: d0d52e7ba57b37506f51412a54a1868f9709561f
5
+ SHA512:
6
+ metadata.gz: 485b9f3d19409c684ffa7062dc3a81ba0aa25331dc20475dc3aa6ecdb09393379c7c997ff2fed94cc9240b5a058607ed74c036b1343710b26ef9496abb5482b8
7
+ data.tar.gz: ab152df1fe540e28a284c45be891cf67c9e9c9113f5b3381773799e6ae69ff680483d160bf17b3aff39d26af4467a7153a30fdb07217e2be64b969fa4a608120
data/LICENSE ADDED
@@ -0,0 +1,53 @@
1
+ Apache License
2
+
3
+ Version 2.0, January 2004
4
+
5
+ http://www.apache.org/licenses/
6
+
7
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
+
9
+ 1. Definitions.
10
+
11
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
16
+
17
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
18
+
19
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
20
+
21
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
22
+
23
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
24
+
25
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
26
+
27
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
28
+
29
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
30
+
31
+ 2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
34
+
35
+ 4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
36
+
37
+ You must give any other recipients of the Work or Derivative Works a copy of this License; and
38
+ You must cause any modified files to carry prominent notices stating that You changed the files; and
39
+ You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
40
+ If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
41
+
42
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
43
+ 5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
44
+
45
+ 6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
46
+
47
+ 7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
48
+
49
+ 8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
50
+
51
+ 9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
52
+
53
+ END OF TERMS AND CONDITIONS
@@ -0,0 +1,144 @@
1
+ iOS Icon Generator
2
+ ============
3
+
4
+ [![Build Status](https://app.bitrise.io/app/b23ec2cde834230f/status.svg?token=IBOm9v8claU8aEpmnLMWig)](https://app.bitrise.io/app/b23ec2cde834230f)
5
+ [![Documentation](https://img.shields.io/badge/docs-available-success.svg)](https://fueled.github.io/ios-icon-generator/)
6
+ [![LICENSE](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0)
7
+
8
+ ## Usage
9
+
10
+ The CLI currently supports 2 commands:
11
+
12
+ - `generate`: generates an iOS App Icon Set from a base PDF
13
+ - `mask`: generates a new iOS App Icon Sets from a base one, adding a mask at its bottom left which can be customized.
14
+ - `stub`: generates a default iOS App Icon Sets, using a background color, a text and its color.
15
+
16
+ ### Installation
17
+
18
+ iOS Icon Generator is built using Ruby, and can be installed using its default local installation in your terminal via:
19
+
20
+ ```bash
21
+ sudo gem install ios_icon_generator
22
+ ```
23
+
24
+ If you wish not to use `sudo` permissions to RubyGems, you can follow the instructions of the `CocoaPods` guys [here](https://guides.cocoapods.org/using/getting-started.html#getting-started), by replacing all `cocoapods` with `ios_icon_generator` in the shell commands.
25
+
26
+ ### Generate App Icon Sets
27
+
28
+ For now, the CLI supports generating app icon sets for all supported platforms:
29
+
30
+ - iPhone
31
+ - iPad
32
+ - Apple Watch
33
+ - Mac
34
+ - Carplay
35
+
36
+ > Please note that the Display P3 is not supported yet
37
+
38
+ And supports generating sticker packs icons for iMessage apps.
39
+
40
+ You can specify iPhone and iPad at the same time, however iMessage must be specified on its own.
41
+
42
+ The base syntax of the command is:
43
+
44
+ ```bash
45
+ icongen generate <PDF Base Icon> [XCAsset Folder] --type=<type>
46
+ ```
47
+
48
+ If the `XCAsset Folder` is not specified, then the current working is assumed to be the output folder.
49
+ The type, if not specified, defaults to `iphone`.
50
+
51
+ For example, to generate icons for iPhones and iPads, and output the images set in `Images.xcassets`, run (assuming the path Icon PDF file is also in the current directory and is called `Icon.pdf`):
52
+ ```bash
53
+ icongen generate Icon.pdf Images.xcassets --type=iphone,ipad
54
+ ```
55
+
56
+ There are more options to `icongen generate` which you can discover by running `icongen generate --help`.
57
+
58
+ ### Masking Existing App Icon Sets
59
+
60
+ The application also supports "masking" app icons, adding a small mask at the bottom-left corner of the icons, allowing for example to convert the following icons:
61
+ ![Before Example](README_Images/Mask-Before.png)
62
+ Into this:
63
+ ![Before Example](README_Images/Mask-After.png)
64
+
65
+ The command used in the example was (it assumes that `AppIcon.appiconset` is the original App Icon Set and is in the current working directory):
66
+ ```bash
67
+ icongen mask AppIcon.appiconset \
68
+ --mask-shape=square \
69
+ --x-size-ratio=0.30 \
70
+ --y-size-ratio=0.30 \
71
+ --size-offset=0.11 \
72
+ --x-offset=0.1 \
73
+ --y-offset=0.1 \
74
+ --background-color='#A36AE9' \
75
+ --stroke-width-offset=0 \
76
+ --font=Symbol \
77
+ --symbol-color='#FFFFFF'
78
+ ```
79
+
80
+ For now, the command only supports adding a mask into the bottom-left corner, but allowing to add it anywhere is definitely a feature we want.
81
+
82
+ The command supports a lot of customization through options, and you can find more information about each option by typing `icongen mask --help`
83
+
84
+ ### Creating temporary icons
85
+
86
+ The application also supports creating "temporary" icons, that you would use during development if you don't have an icon yet (for example at project creation). For example, here are some icons created using various commands:
87
+
88
+ ![Icons Example](README_Images/Icons-Example.png)
89
+
90
+ Here's the command that were run to get each icons above:
91
+ ```bash
92
+ #1
93
+ icongen stub \
94
+ WS \
95
+ --background-color='#A36AE9' \
96
+ --stroke-width-offset=0 \
97
+ --y-offset=-0.04 \
98
+ --size-offset=0.5 \
99
+ --symbol-color='#FFFFFF'
100
+ ```
101
+ ```bash
102
+ #2
103
+ icongen stub \
104
+ W \
105
+ --background-color='#3A7D31' \
106
+ --font=Symbol \
107
+ --stroke-width-offset=0.01 \
108
+ --y-offset=-0.07 \
109
+ --size-offset=0.5 \
110
+ --symbol-color='#C9C9C9'
111
+ ```
112
+ ```bash
113
+ #3
114
+ icongen stub \
115
+ A \
116
+ --background-color='#000000' \
117
+ --stroke-width-offset=0.01 \
118
+ --stroke-color='#FFFFFF' \
119
+ --font='Arial' \
120
+ --size-offset=0.5 \
121
+ --symbol-color='#000000'
122
+ ```
123
+
124
+ The command supports a lot of customization through options, and you can find more information about each option by typing `icongen stub --help`.
125
+
126
+ ## Development
127
+
128
+ ### Set Up
129
+
130
+ To set you up for developing on driveshaft, first make sure the repository is cloned and you're in its root folder, and then run the following:
131
+
132
+ ```bash
133
+ echo "BUNDLE_GEMFILE=\"`pwd`/Gemfile\" bundler exec ruby \"`pwd`/bin/icongen\" \"\${@---help}\"" > /usr/local/bin/icongen-dev
134
+ chmod +x /usr/local/bin/icongen-dev
135
+ ```
136
+
137
+ All you'll be all set!
138
+ To run the development version of `icongen` from anywhere, just run `icongen-dev` rather than `icongen`.
139
+ You can then proceed on developing locally on the ios-icon-generator repository, and create a PR whenever a new piece of code is ready to be reviewed and integrated!
140
+
141
+ To run the test suite, you may run the following command from the root folder:
142
+ ```bash
143
+ bundler exec ruby bin/rspec -I .
144
+ ```
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require 'ios_icon_generator'
5
+
6
+ arguments = ARGV
7
+ trace_enabled = arguments.include?('--trace')
8
+ arguments.reject! { |v| v == '--trace' }
9
+
10
+ begin
11
+ Hanami::CLI.new(IOSIconGenerator::CLI::Commands).call(arguments: arguments)
12
+ rescue StandardError => e
13
+ raise if trace_enabled
14
+
15
+ puts "ERROR: #{e.message}".red
16
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2019 Fueled Digital Media, LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'ios_icon_generator/version'
18
+ require 'rubygems'
19
+ require 'colored2'
20
+ require 'hanami/cli'
21
+
22
+ # The IOSIconGenerator module
23
+ module IOSIconGenerator
24
+ # :nodoc:
25
+ module CLI
26
+ # :nodoc:
27
+ module Commands
28
+ extend Hanami::CLI::Registry
29
+ end
30
+ end
31
+
32
+ ##
33
+ # The helpers used by the commands of IOSIconGenerator.
34
+ module Helpers
35
+ end
36
+ end
37
+
38
+ require 'ios_icon_generator/cli/commands/generate'
39
+ require 'ios_icon_generator/cli/commands/mask'
40
+ require 'ios_icon_generator/cli/commands/stub'
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2019 Fueled Digital Media, LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'colored2'
18
+ require 'parallel'
19
+ require 'ruby-progressbar'
20
+ require 'ios_icon_generator/helpers/generate_icon'
21
+ require 'ios_icon_generator/helpers/which'
22
+ require 'hanami/cli'
23
+
24
+ module IOSIconGenerator
25
+ module CLI
26
+ module Commands
27
+ class Generate < Hanami::CLI::Command
28
+ desc 'Generate app icons'
29
+ argument :icon_path, required: true, desc: 'The unmasked pdf icon. The icon must be at least 1024x1024'
30
+ argument :xcasset_folder, default: '.', desc: "The path to your .xcassets folder. \
31
+ If not specified, the appiconsets will be generated in the current folder and can be draged\'n\'dropped there in xcode"
32
+ option :type, type: :array, default: %w[iphone], desc: 'Which target to generate the icons for. Can be "iphone", "ipad", "watch", "mac" or "carplay" or a combination of any of them, or "imessage"'
33
+ option :parallel_processes, type: :integer, default: -1, desc: 'Number of processes to use to process the files. Defaults to -1, meaning the number of cores the machine. \
34
+ Set to 0 to disable parallel processing.'
35
+ def call(icon_path:, xcasset_folder:, type:, **options)
36
+ raise "#{'ImageMagick'.blue.bold} is required. It can be installed via #{'homebrew'.bold.underlined} using #{'brew install imagemagick'.blue.bold.underlined}" unless Library.which('magick')
37
+
38
+ types = type.map(&:to_sym)
39
+
40
+ progress_bar = ProgressBar.create(total: nil)
41
+
42
+ parallel_processes = options.fetch(:parallel_processes).to_i
43
+ parallel_processes = nil if parallel_processes == -1
44
+ Helpers.generate_icon(
45
+ icon_path: icon_path,
46
+ output_folder: xcasset_folder,
47
+ types: types,
48
+ parallel_processes: parallel_processes,
49
+ progress: lambda do |progress, total|
50
+ progress_bar.total = total unless progress_bar.total
51
+ progress_bar.increment if progress
52
+ end
53
+ )
54
+ puts "\nCompleted!".green
55
+ end
56
+ end
57
+
58
+ register 'generate', Commands::Generate
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2019 Fueled Digital Media, LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'fileutils'
18
+ require 'base64'
19
+ require 'colored2'
20
+ require 'parallel'
21
+ require 'ruby-progressbar'
22
+ require 'ios_icon_generator/helpers/mask_icon'
23
+ require 'hanami/cli'
24
+
25
+ module IOSIconGenerator
26
+ module CLI
27
+ module Commands
28
+ module Build
29
+ class Icon < Hanami::CLI::Command
30
+ desc 'Generate app icons'
31
+ argument :appiconset_path, required: true, desc: 'The unmasked pdf icon. The icon must be at least 1024x1024'
32
+ argument :output_path, default: '.', desc: "The path to your .xcassets folder. \
33
+ If not specified, the appiconsets will be generated in the current folder and can be draged\'n\'dropped there in xcode"
34
+ option :suffix, default: 'Beta', desc: 'The prefix to add to the original app icon set'
35
+ option :background_color, default: '#FFFFFF', desc: 'The background color of the mask'
36
+ option :stroke_color, default: '#000000', desc: 'The stroke color of the mask'
37
+ option :stroke_width_offset, type: :float, default: 0.01, desc: 'The width of the stroke used when generating the mask\'s background.'
38
+ option :symbol, default: 'b', desc: 'The symbol to use to generate the mask.'
39
+ option :symbol_color, default: '#7F0000', desc: 'The color of the symbol to use to generate the mask.'
40
+ option :font, default: 'Helvetica', desc: 'The font to use to generate the symbol.'
41
+ option :file, default: nil, desc: 'The path to an image representing the symbol to use to generate the mask.'
42
+ option :x_size_ratio, type: :float, default: 0.46, desc: 'The x offset of the size of the mask.'
43
+ option :y_size_ratio, type: :float, default: 0.46, desc: 'The y offset of the size of the mask.'
44
+ option :size_offset, type: :float, default: 0.12, desc: 'The size offset to use when applying the symbol. 0.0 means it\'s scale to the full image, 1.0 means the symbol has the full size of the logo.'
45
+ option :x_offset, type: :float, default: 0.11, desc: 'The x offset to use when applying the symbol. 0.0 means bottom, 1.0 means top.'
46
+ option :y_offset, type: :float, default: 0.11, desc: 'The y offset to use when applying the symbol. 0.0 means left, 1.0 means top.'
47
+ option :mask_shape, default: 'triangle', desc: 'The shape of the form. Can only be either of \'triangle\' or \'square\'.'
48
+ option :parallel_processes, type: :integer, default: -1, desc: 'Number of processes to use to process the files. Defaults to -1, meaning the number of cores the machine. \
49
+ Set to 0 to disable parallel processing.'
50
+ def call(appiconset_path:, output_path:, **options)
51
+ raise "#{'ImageMagick'.blue.bold} is required. It can be installed via #{'homebrew'.bold.underlined} using #{'brew install imagemagick'.blue.bold.underlined}" unless Library.which('magick')
52
+
53
+ raise 'There is no App icon set at the path specified.' unless Dir.exist?(appiconset_path)
54
+
55
+ progress_bar = ProgressBar.create(total: nil)
56
+ parallel_processes = options.fetch(:parallel_processes).to_i
57
+ parallel_processes = nil if parallel_processes == -1
58
+ Helpers.mask_icon(
59
+ appiconset_path: appiconset_path,
60
+ output_folder: output_path,
61
+ mask: {
62
+ background_color: options.fetch(:background_color),
63
+ stroke_color: options.fetch(:stroke_color),
64
+ stroke_width_offset: options.fetch(:stroke_width_offset)&.to_f,
65
+ suffix: options.fetch(:suffix),
66
+ symbol: options.fetch(:symbol),
67
+ symbol_color: options.fetch(:symbol_color),
68
+ font: options.fetch(:font),
69
+ file: options[:file],
70
+ x_size_ratio: options.fetch(:x_size_ratio)&.to_f,
71
+ y_size_ratio: options.fetch(:y_size_ratio)&.to_f,
72
+ size_offset: options.fetch(:size_offset)&.to_f,
73
+ x_offset: options.fetch(:x_offset)&.to_f,
74
+ y_offset: options.fetch(:y_offset)&.to_f,
75
+ shape: options.fetch(:mask_shape)&.to_sym,
76
+ },
77
+ parallel_processes: parallel_processes,
78
+ progress: lambda do |progress, total|
79
+ progress_bar.total = total unless progress_bar.total
80
+ progress_bar.increment if progress
81
+ end
82
+ )
83
+ puts 'Completed!'.green
84
+ end
85
+ end
86
+ end
87
+
88
+ register 'mask', Build::Icon
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright (c) 2019 Fueled Digital Media, LLC
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+
17
+ require 'colored2'
18
+ require 'parallel'
19
+ require 'ruby-progressbar'
20
+ require 'ios_icon_generator/helpers/generate_icon'
21
+ require 'ios_icon_generator/helpers/which'
22
+ require 'hanami/cli'
23
+
24
+ module IOSIconGenerator
25
+ module CLI
26
+ module Commands
27
+ class Stub < Hanami::CLI::Command
28
+ desc 'Generate stub app icons'
29
+ argument :text, required: true, desc: 'The text to use when generating the icon.'
30
+ argument :xcasset_folder, default: '.', desc: "The path to your .xcassets folder. \
31
+ If not specified, the appiconsets will be generated in the current folder and can be draged\'n\'dropped there in xcode"
32
+ option :background_color, default: '#FFFFFF', desc: 'The background color of the mask'
33
+ option :symbol, default: 'b', desc: 'The symbol to use.'
34
+ option :font, default: 'Helvetica', desc: 'The font to use to generate the symbol.'
35
+ option :symbol_color, default: '#7F0000', desc: 'The color of the symbol to use to generate the mask.'
36
+ option :stroke_color, default: '#000000', desc: 'The stroke color of the mask'
37
+ option :stroke_width_offset, type: :float, default: 0.1, desc: 'The width of the stroke used when generating the symbol.'
38
+ option :size_offset, type: :float, default: 0.5, desc: 'The point size used for the symbol, relative to the height of the icon. Values over 0.5 are not recommended.'
39
+ option :x_offset, type: :float, default: 0.0, desc: 'The x offset to use when applying the symbol. 0.0 means bottom, 1.0 means top.'
40
+ option :y_offset, type: :float, default: 0.0, desc: 'The y offset to use when applying the symbol. 0.0 means left, 1.0 means top.'
41
+ option :type, type: :array, default: %w[iphone], desc: 'Which target to generate the icons for. Can be "iphone", "ipad", "watch", "mac" or "carplay" or a combination of any of them, or "imessage"'
42
+ option :parallel_processes, type: :integer, default: -1, desc: 'Number of processes to use to process the files. Defaults to -1, meaning the number of cores the machine. \
43
+ Set to 0 to disable parallel processing.'
44
+ def call(text:, xcasset_folder:, type:, **options)
45
+ raise "#{'ImageMagick'.blue.bold} is required. It can be installed via #{'homebrew'.bold.underlined} using #{'brew install imagemagick'.blue.bold.underlined}" unless Library.which('magick')
46
+
47
+ types = type.map(&:to_sym)
48
+
49
+ progress_bar = ProgressBar.create(total: nil)
50
+
51
+ parallel_processes = options.fetch(:parallel_processes).to_i
52
+ parallel_processes = nil if parallel_processes == -1
53
+ Helpers.generate_icon(
54
+ icon_path: nil,
55
+ output_folder: xcasset_folder,
56
+ types: types,
57
+ parallel_processes: parallel_processes,
58
+ generate_icon: lambda do |_base_path, target_path, width, height|
59
+ system(
60
+ 'magick',
61
+ '-size',
62
+ "#{width}x#{height}",
63
+ "xc:#{options.fetch(:background_color)}",
64
+ '-strokewidth',
65
+ (options.fetch(:stroke_width_offset).to_f * [width, height].min).to_s,
66
+ '-stroke',
67
+ (options.fetch(:stroke_width_offset).to_f.zero? ? 'none' : options.fetch(:stroke_color)).to_s,
68
+ '-fill',
69
+ options.fetch(:symbol_color),
70
+ '-gravity',
71
+ 'center',
72
+ '-font',
73
+ options.fetch(:font),
74
+ '-pointsize',
75
+ (height * options.fetch(:size_offset).to_f).to_s,
76
+ '-annotate',
77
+ "+#{width * options.fetch(:x_offset).to_f}+#{height * -options.fetch(:y_offset).to_f}",
78
+ text,
79
+ target_path
80
+ )
81
+ end,
82
+ progress: lambda do |progress, total|
83
+ progress_bar.total = total unless progress_bar.total
84
+ progress_bar.increment if progress
85
+ end
86
+ )
87
+ puts "\nCompleted!".green
88
+ end
89
+ end
90
+
91
+ register 'stub', Commands::Stub
92
+ end
93
+ end
94
+ end