retinator 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: c401027d0c6d29f925b6e243600b1f11c2276485
4
+ data.tar.gz: 75482b368b08a188053ae225f20f14f88a4fa52b
5
+ SHA512:
6
+ metadata.gz: b049df9236a269f599ed84e35b3eacf4a790f87409df708e2a72bfde093c3ff53e55f1991c37b89686e6eadd93c3ef7833ff945b6f91a326539dded08c38a542
7
+ data.tar.gz: 9a288ac7002757bb0d9e5e2b872e9769ae3aef14dfb46302380c82bdc96afa96f6add4355de1d67915c218ac719d9f0d41237f8a5c5aeb6e163ccdcf51f80d18
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ ## Specific to RubyMotion:
17
+ .dat*
18
+ .repl_history
19
+ build/
20
+ *.bridgesupport
21
+ build-iPhoneOS/
22
+ build-iPhoneSimulator/
23
+
24
+ ## Specific to RubyMotion (use of CocoaPods):
25
+ #
26
+ # We recommend against adding the Pods directory to your .gitignore. However
27
+ # you should judge for yourself, the pros and cons are mentioned at:
28
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
29
+ #
30
+ # vendor/Pods/
31
+
32
+ ## Documentation cache and generated files:
33
+ /.yardoc/
34
+ /_yardoc/
35
+ /doc/
36
+ /rdoc/
37
+
38
+ ## Environment normalization:
39
+ /.bundle/
40
+ /vendor/bundle
41
+ /lib/bundler/man/
42
+
43
+ # for a library or gem, you might want to ignore these files since the code is
44
+ # intended to run in multiple environments; otherwise, check them in:
45
+ # Gemfile.lock
46
+ # .ruby-version
47
+ # .ruby-gemset
48
+
49
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
50
+ .rvmrc
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.3
5
+ before_install: gem install bundler -v 1.16.1
@@ -0,0 +1,65 @@
1
+ {
2
+ // Utilizar IntelliSense para aprender acerca de los posibles atributos.
3
+ // Mantenga el puntero para ver las descripciones de los existentes atributos
4
+ // Para más información, visite: https://go.microsoft.com/fwlink/?linkid=830387
5
+ "version": "0.2.0",
6
+ "configurations": [
7
+ {
8
+ "name": "Run Vertical Test",
9
+ "type": "Ruby",
10
+ "request": "launch",
11
+ "cwd": "${workspaceRoot}",
12
+ "program": "${workspaceRoot}/bin/retinator",
13
+ "args": [
14
+ "${workspaceRoot}/test/vertical.jpg",
15
+ "150"
16
+ ]
17
+ },
18
+ {
19
+ "name": "Run Horizontal Test",
20
+ "type": "Ruby",
21
+ "request": "launch",
22
+ "cwd": "${workspaceRoot}",
23
+ "program": "${workspaceRoot}/bin/retinator",
24
+ "args": [
25
+ "${workspaceRoot}/test/horizontal.jpg",
26
+ "150"
27
+ ]
28
+ },
29
+ {
30
+ "name": "Run Help Test",
31
+ "type": "Ruby",
32
+ "request": "launch",
33
+ "cwd": "${workspaceRoot}",
34
+ "program": "${workspaceRoot}/bin/retinator"
35
+ },
36
+ {
37
+ "name": "No Arguments Test",
38
+ "type": "Ruby",
39
+ "request": "launch",
40
+ "cwd": "${workspaceRoot}",
41
+ "program": "${workspaceRoot}/bin/retinator"
42
+ },
43
+ {
44
+ "name": "Wrong Flag Test",
45
+ "type": "Ruby",
46
+ "request": "launch",
47
+ "cwd": "${workspaceRoot}",
48
+ "program": "${workspaceRoot}/bin/retinator",
49
+ "args": [
50
+ "-l"
51
+ ]
52
+ },
53
+ {
54
+ "name": "Wrong Arguments Test",
55
+ "type": "Ruby",
56
+ "request": "launch",
57
+ "cwd": "${workspaceRoot}",
58
+ "program": "${workspaceRoot}/bin/retinator",
59
+ "args": [
60
+ "nofile",
61
+ "200"
62
+ ]
63
+ }
64
+ ]
65
+ }
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in retinator.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,26 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ retinator (0.1.1)
5
+ colorize (~> 0.8.1)
6
+ mini_magick (~> 4.8)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ colorize (0.8.1)
12
+ mini_magick (4.8.0)
13
+ minitest (5.11.1)
14
+ rake (10.5.0)
15
+
16
+ PLATFORMS
17
+ ruby
18
+
19
+ DEPENDENCIES
20
+ bundler (~> 1.16)
21
+ minitest (~> 5.0)
22
+ rake (~> 10.0)
23
+ retinator!
24
+
25
+ BUNDLED WITH
26
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Mario Negro
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
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,51 @@
1
+ # Retinator [![Build Status](https://travis-ci.org/emenegro/retinator.svg?branch=master)](https://travis-ci.org/emenegro/retinator)
2
+
3
+ Retinator resizes the source image and generates three images in @1x, @2x and @3x iOS resolutions.
4
+
5
+ ![retinator-gif](etc/retinator.gif)
6
+
7
+ ## Usage
8
+
9
+ ```
10
+ retinator [source_image] [destination_resolution]
11
+ retinator --help
12
+ ```
13
+
14
+ - `[source_image]`: path to the source image
15
+ - `[destination_resolution]`: a number indicating the resolution of the smaller dimension of the destination @1x image
16
+
17
+ ### Example
18
+
19
+ For an input image of 3000x1500, `retinator test.jpg 200` will output:
20
+
21
+ ```
22
+ test.png   (400x200)
23
+ test@2x.png (800x400)
24
+ test@3x.png (1200x600)
25
+ ```
26
+
27
+ ## Installation
28
+
29
+ This gem needs ImageMagick or GraphicksMagick in order to run. It has to be installed using a [brew](https://brew.sh) formula. Run this command in your terminal:
30
+
31
+ ```
32
+ brew install graphicsmagick
33
+ ```
34
+
35
+ After that you can install the tool the usual way:
36
+
37
+ ```
38
+ gem install retinator
39
+ ```
40
+
41
+ Or, in dev mode:
42
+
43
+ ```
44
+ bundle install
45
+ gem build retinator.gemspec
46
+ gem install retinator-[VERSION].gem
47
+ ```
48
+
49
+ ## TODO
50
+
51
+ - Allow batch processing
data/Rakefile ADDED
@@ -0,0 +1,15 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require 'rubygems/package_task'
4
+
5
+ spec = eval(File.read('retinator.gemspec'))
6
+ Gem::PackageTask.new(spec) do |pkg|
7
+ end
8
+
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << "test"
11
+ t.libs << "lib"
12
+ t.test_files = FileList["test/**/*_test.rb"]
13
+ end
14
+
15
+ task :default => :test
data/bin/retinator ADDED
@@ -0,0 +1,56 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "retinator"
4
+ require "colorize"
5
+ require "optparse"
6
+
7
+ # Graceful exit
8
+ Signal.trap("INT") do
9
+ puts "\nRemoving partially generated images...".blue
10
+ Retinator.remove_files_on_abort
11
+ exit
12
+ end
13
+
14
+ options = {}
15
+ option_parser = OptionParser.new do |opts|
16
+ opts.banner = "Usage: #{File.basename($PROGRAM_NAME)} source_image destination_resolution
17
+
18
+ Retinator resizes the source image and generates
19
+ three images in @1x, @2x and @3x iOS resolutions
20
+
21
+ - source_image: path to the source image
22
+ - destination_resolution: a number indicating the minimum resolution
23
+ of the smaller dimension of the destination @1x image
24
+
25
+ Example: for an input image of 3000x1500, 'retinator test.jpg 200' will output:
26
+ test.png (400x200)
27
+ test@2x.png (800x400)
28
+ test@3x.png (1200x600)
29
+ "
30
+ end
31
+
32
+ begin
33
+ option_parser.parse!
34
+
35
+ if ARGV.count != 2
36
+ puts option_parser
37
+ exit 1
38
+ end
39
+
40
+ file = ARGV.shift
41
+ if !File.exist? file
42
+ puts "Error, no file found at '#{file}'".red
43
+ exit 1
44
+ end
45
+
46
+ res = ARGV.shift.to_i
47
+ if res <= 0
48
+ puts "Error, destination resolution has to be a number greater than 0".red
49
+ exit 1
50
+ end
51
+
52
+ Retinator.generate file, res
53
+ rescue OptionParser::InvalidOption => ex
54
+ puts "Error, #{ex.message}".red
55
+ exit 1
56
+ end
data/etc/retinator.gif ADDED
Binary file
@@ -0,0 +1,8 @@
1
+ OUTPUT_MAX_SCALE = 3
2
+ OUTPUT_FORMAT = "png"
3
+ OUTPUTS = [
4
+ # [RESOLUTION MULTIPLIER, FILE SUFFIX]
5
+ [1, ""],
6
+ [2, "@2x"],
7
+ [3, "@3x"]
8
+ ]
@@ -0,0 +1,8 @@
1
+ module Utils
2
+ class << self
3
+ def filename(path)
4
+ extension = File.extname path
5
+ return File.basename path, extension
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Retinator
2
+ VERSION = "0.1.1"
3
+ end
data/lib/retinator.rb ADDED
@@ -0,0 +1,67 @@
1
+ require "mini_magick"
2
+ require "colorize"
3
+ require "fileutils"
4
+ require_relative "retinator/version"
5
+ require_relative "retinator/config"
6
+ require_relative "retinator/utils"
7
+
8
+ module Retinator
9
+ class << self
10
+ def generate(path, res)
11
+ return false unless check_params path, res
12
+ show_dimension_hint_if_needed path, res
13
+ generate_images path, res
14
+ return true
15
+ end
16
+
17
+ def remove_files_on_abort
18
+ @saved_files.each do |file|
19
+ FileUtils.rm file
20
+ end
21
+ @saved_files.clear
22
+ end
23
+
24
+ private def check_params(path, res)
25
+ return false unless path && res
26
+ return false unless File.exist? path
27
+ return false unless res.kind_of? Integer
28
+ return false unless res > 0
29
+ return true
30
+ end
31
+
32
+ private def generate_images(path, res)
33
+ @saved_files = []
34
+ name = Utils.filename path
35
+ OUTPUTS.each do |config|
36
+ scale = config[0]
37
+ suffix = config[1]
38
+ filename = "#{name}#{suffix}.#{OUTPUT_FORMAT}"
39
+ puts "Generating #{filename}..."
40
+ image = resize path, res * scale
41
+ save_file image, filename, OUTPUT_FORMAT
42
+ end
43
+ puts "Done!".green
44
+ @saved_files.clear
45
+ end
46
+
47
+ private def show_dimension_hint_if_needed(path, res)
48
+ image = MiniMagick::Image.open(path)
49
+ smaller_dimensions = image.dimensions.select { |d| d <= res * OUTPUT_MAX_SCALE}
50
+ if !smaller_dimensions.empty?
51
+ puts "[!] Size of the source image is smaller than the destination resolution".yellow
52
+ puts " Result images could be pixelated".yellow
53
+ end
54
+ end
55
+
56
+ private def resize(path, res)
57
+ image = MiniMagick::Image.open path
58
+ return image.resize("#{res}x#{res}^")
59
+ end
60
+
61
+ private def save_file(image, filename, format)
62
+ image.format format
63
+ image.write filename
64
+ @saved_files << filename
65
+ end
66
+ end
67
+ end
data/retinator.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ lib = File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "retinator/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "retinator"
7
+ spec.version = Retinator::VERSION
8
+ spec.authors = ["Mario Negro"]
9
+ spec.email = ["mario.negro.martin@gmail.com"]
10
+
11
+ spec.summary = "Generates @1x, @2x and @3x images versions of an image"
12
+ spec.description = "Generates @1x, @2x and @3x images versions of an image for iOS projects"
13
+ spec.homepage = "https://github.com/emenegro/retinator"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
17
+ f.match(%r{^(test|spec|features)/})
18
+ end
19
+ spec.bindir = "bin"
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.require_paths = ["lib"]
22
+
23
+ spec.add_runtime_dependency "colorize", "~> 0.8.1"
24
+ spec.add_runtime_dependency "mini_magick", "~> 4.8"
25
+ spec.add_development_dependency "bundler", "~> 1.16"
26
+ spec.add_development_dependency "rake", "~> 10.0"
27
+ spec.add_development_dependency "minitest", "~> 5.0"
28
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: retinator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Mario Negro
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-01-25 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: colorize
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.8.1
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.8.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: mini_magick
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.8'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.8'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.16'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.16'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: minitest
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '5.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '5.0'
83
+ description: Generates @1x, @2x and @3x images versions of an image for iOS projects
84
+ email:
85
+ - mario.negro.martin@gmail.com
86
+ executables:
87
+ - retinator
88
+ extensions: []
89
+ extra_rdoc_files: []
90
+ files:
91
+ - ".gitignore"
92
+ - ".travis.yml"
93
+ - ".vscode/launch.json"
94
+ - Gemfile
95
+ - Gemfile.lock
96
+ - LICENSE.txt
97
+ - README.md
98
+ - Rakefile
99
+ - bin/retinator
100
+ - etc/retinator.gif
101
+ - lib/retinator.rb
102
+ - lib/retinator/config.rb
103
+ - lib/retinator/utils.rb
104
+ - lib/retinator/version.rb
105
+ - retinator.gemspec
106
+ homepage: https://github.com/emenegro/retinator
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.5.2
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Generates @1x, @2x and @3x images versions of an image
130
+ test_files: []