lgtm_hd 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c41c2e01a27d7f6c8d8abeb1ab55d879c7301af8
4
- data.tar.gz: 8276a44c7526c9fa68f5fbebba7b58b4049b84c8
3
+ metadata.gz: ff6fc3e47abef583c5dc6070508c93cef024e6da
4
+ data.tar.gz: aed3e2c80b96d2c35b65b9b9f365aa70e770e9a4
5
5
  SHA512:
6
- metadata.gz: 6421eb054e6a2872df460ffc5a8b6c3603a8a94faaddef6b6e9ca52beed0e3004e8dd3e75801f3c087d7ba03ccd3c91e7895f89393b9d6e5689863f7e5743350
7
- data.tar.gz: a2703a165f8e37526decb537b1f9aa4d89c02dc0f8a89a16a8265ac2cff18cdd810e86d635a640b4097e435a3dcc8effee80e0aa581164d3a8fb64b0347639e1
6
+ metadata.gz: a7c02822fbaec53939193c8245a414d322558c4825330aab6f0c5e93d5c6aac8e7cb5a50b200598bb9cbfca9d0c81edb2ba5187c150e747856343c3bbd73f811
7
+ data.tar.gz: 29c6b9830a8773e094af8762397c0d6c99cd45d280af11430e83c4b8044a78b1abb0c7243ee6b612a77f64147da46b316bb937a15555c65298a0e0f0c21ef5e1
@@ -0,0 +1,8 @@
1
+ ## 0.3.0
2
+ - Added live image previewing and option --preview
3
+ - Fixed ?querystring after extension name
4
+ ## 0.2.x
5
+ - Added command random for fetching LGTM image from LGTM.in
6
+ - Improved CLI UI/UX
7
+ ## 0.1.0
8
+ - The Big bang
data/README.md CHANGED
@@ -16,36 +16,82 @@ Source | Happy Taeyeon!
16
16
  :-------------------------:|:-------------------------:
17
17
  ![](./images/example_2_before.png?raw=true) | ![](./images/example_2_after.jpg?raw=true)
18
18
 
19
+ ## Requirements
20
+
21
+ This gem needs [imagemagick](https://www.imagemagick.org/) installed on local machine for image processing
22
+
23
+ See if it has been installed already (should be able to see similar output like below)
24
+
25
+ $ convert -version
26
+ Version: ImageMagick 6.9.2-6 Q16 x86_64 2015-11-15 http://www.imagemagick.org
27
+ Copyright: Copyright (C) 1999-2015 ImageMagick Studio LLC
28
+
29
+ If not, follow below command to install it
30
+
31
+ # for Ubuntu, Debian
32
+ $ sudo apt-get install imagemagick libmagickwand-dev
33
+
34
+ # for RHEL, CentOS, Fedora
35
+ $ yum install -y ImageMagick ImageMagick-devel
36
+
37
+ # Mac with Brew
38
+ $ brew install imagemagick
39
+ # Mac with Port
40
+ $ sudo port install imagemagick
19
41
 
20
42
  ## Installation
21
43
 
22
44
  $ gem install lgtm_hd
23
-
45
+
24
46
  ## Usage
25
47
 
48
+ Add LGTM caption to image
49
+
26
50
  $ lgtm_hd <source_image_uri>
51
+
52
+ Fetch random image from LGTM.in
53
+
27
54
  $ lgtm_hd random
28
55
 
29
- Options:
30
- --clipboard (or -c) will let the OS copy content of the file for direct pasting to Github comment box
56
+ Global Options:
57
+
31
58
  --interactive (or -i) is for lazy people who can't bother to type
32
59
  --dest DIR (or -d) is for changing output folder
33
60
  Default command is transform so you can just leave the command empty.
34
61
 
35
- ## Examples
62
+ ## Examples
63
+
64
+ Add LGTM caption to image (with output)
65
+
66
+ $ lgtm_hd http://nogitweet.com/wp-content/uploads/2015/03/fbf5c1c80ffea521bad6e231061731a5.gif
67
+ Reading and inspecting source at http://nogitweet.com/wp-content/uploads/2015/03/fbf5c1c80ffea521bad6e231061731a5.gif
68
+ Transforming Image
69
+ Exporting to file
70
+ Exported LGTM image to /Users/huydq/Desktop/lgtm_hd_20170529005457.gif
71
+ Copied file to OS's clipboard for direct pasting to Github comments or Slack
72
+
73
+ Fetch random image from LGTM.in (with output)
74
+
75
+ $ bundle exec bin/lgtm_hd random
76
+ Fetching from lgtm.in
77
+ Loading image at http://www.storyofbing.com/pics3/ff0040_kids_thumbs_up_sharp_mooiplaas.jpg
78
+ Exported image to /Users/huydq/Works/lgtm_hd/lgtm_hd_20170529011541.jpg
79
+ Copied file to OS's clipboard for direct pasting to Github comments or Slack
80
+
81
+ Or you can copy the markdown format below provided by lgtm.in
82
+ [![LGTM](https://lgtm.in/p/mdVnGXxym)](https://lgtm.in/i/mdVnGXxym)
83
+
84
+ if the lgtm.in's image does not have LGTM texts on it, run the cmd below
85
+ lgtm_hd /Users/huydq/Works/lgtm_hd/lgtm_hd_20170529011541.jpg
86
+
87
+ Interaction Mode
36
88
 
37
- $ lgtm_hd transform http://nogitweet.com/wp-content/uploads/2015/03/fbf5c1c80ffea521bad6e231061731a5.gif
38
- \ Reading and inspecting source at http://nogitweet.com/wp-content/uploads/2015/03/fbf5c1c80ffea521bad6e231061731a5.gif
39
- \ Processing Image
40
- \ Exporting to file
41
- \ Exported LGTM image to /Users/huydq/Desktop/lgtm_hd_20170527124831.gif.
89
+ $ lgtm_hd -i
90
+ -- LGTM HD Interactive Mode --
91
+ Source Image (URL or Path/to/file): lgtm_hd_20170527122725.jpg
92
+ Destination Directory (Enter to skip):
93
+ ...
42
94
 
43
- $ lgtm_hd random -c -d /tmp/
44
- \ Fetching random image from lgtm.in
45
- \ Loading image at http://i.imgur.com/mHrrwpY.gif
46
- \ Exported image to /tmp/lgtm_hd_20170527124027.gif
47
- \ Copied file to OS's clipboard for direct pasting to Github comments or Slack
48
- \ Or you can copy the markdown format by lgtm.in directly below
49
95
 
50
96
  ## Features
51
97
 
@@ -53,6 +99,7 @@ Source | Happy Taeyeon!
53
99
  * Source Image - Support Offline (file) or Online (url)
54
100
  * Caption Position - Top Center or Bottom Center positions for the caption
55
101
  * Auto Clipboard - MacOSX user can just paste directly to comment box on Github after running the programm. On other OSes the clipboard only returns the path to the generated LGTM image.
102
+ * Random image from LGTM.in
56
103
  * Formats - GIF, PNG, JPEG (SVG and TIFF not tested yet)
57
104
  * Max Image size is 500px by 500px
58
105
 
@@ -62,9 +109,8 @@ Source | Happy Taeyeon!
62
109
  * Add options for \[font size, positions\] (Code already setup for this, expect new version soon!)
63
110
  * Add --source-random option incase there is no source provided.
64
111
  * Add --caption-color for more colorful captions
65
- * Integration to lgtm.in
66
- * Submission to lgtm.in
67
- * Query lgtm or google images and return the first found item
112
+ * Submission to lgtm.in
113
+ * Keyword's based Query google images and return the first found item
68
114
  * Interactive mode with image preview in ASCII generation
69
115
  * Interactive mode that allow adjusting LGTM captions
70
116
  * Add progress bar for the whole generation process
@@ -11,10 +11,11 @@ Gem::Specification.new do |spec|
11
11
  spec.authors = ["Huy Dinh"]
12
12
  spec.email = ["phradion@gmail.com"]
13
13
 
14
- spec.summary = %q{CLI tool for generating images from user input with LGTM text on it, or fetching images from LGTM.in based on user's query. Finally put the image to clipboard. Support direct image pasting to Github and Slack on MacOSX.}
14
+ spec.summary = %q{CLI tool for generating images from user input with LGTM text on it, or fetching images from LGTM.in based on user's query. Finally put the image to clipboard. Support direct image pasting to Github and Slack on MacOSX. Live preview on terminal as well!}
15
15
  spec.description = %q{This gem is command-line tool for fetching random image from lgtm.in.
16
16
  It also provide tool to apply LGTM text based on input file/url with smart text colors and positions.
17
- It also support direct clipboard paste to github's comment box or Slack on MacOSX.}
17
+ It also support direct clipboard paste to github's comment box or Slack on MacOSX.
18
+ Live preview on terminal as well!}
18
19
  spec.homepage = "http://github.com/phradion/lgtm_hd"
19
20
  spec.license = "MIT"
20
21
 
@@ -37,8 +38,9 @@ Gem::Specification.new do |spec|
37
38
  spec.add_development_dependency "rspec", "3.6.0"
38
39
  spec.add_development_dependency "simplecov"
39
40
  spec.add_development_dependency "codeclimate-test-reporter", "~> 1.0.0"
40
- spec.add_runtime_dependency "commander", "4.4.3"
41
- spec.add_runtime_dependency "clipboard", "1.1.1"
42
- spec.add_runtime_dependency "os", "1.0.0"
43
- spec.add_runtime_dependency "mini_magick", "4.7.0"
41
+ spec.add_runtime_dependency "commander", "~> 4.4.3"
42
+ spec.add_runtime_dependency "catpix_mini", "~> 0.1.0", ">= 0.1.0"
43
+ spec.add_runtime_dependency "clipboard", "~> 1.1.1"
44
+ spec.add_runtime_dependency "os", "~> 1.0.0"
45
+ spec.add_runtime_dependency "mini_magick", "~> 4.7.0"
44
46
  end
@@ -2,23 +2,27 @@ require 'rubygems'
2
2
  require 'commander'
3
3
  require 'os'
4
4
  require 'clipboard'
5
+ require 'catpix_mini'
5
6
  require 'uri'
6
7
 
7
8
  module LgtmHD
8
9
  class CLI
9
10
  include Commander::Methods
10
11
 
11
- CMD_RANDOM_SYNTAX = 'lgtm_hd random [-i | --interactive] [-d | --dest DIR]'.freeze
12
- CMD_TRANSFORM_SYNTAX = 'lgtm_hd <URI|FILE> [-i | --interactive] [-d | --dest <DIR>]'.freeze
12
+ CMD_RANDOM_SYNTAX = 'lgtm_hd random [options]'.freeze
13
+ CMD_TRANSFORM_SYNTAX = 'lgtm_hd <URI|FILE> [options]'.freeze
14
+ OPTIONS_SYNTAX = '[-i | --interactive] [-d | --destination <DIR>] [-p | --preview high|low|none]'
13
15
 
14
16
  def run
15
17
  program :name, LgtmHD::Configuration::PROGRAM_NAME
16
18
  program :version, LgtmHD::VERSION
17
19
  program :description, LgtmHD::Configuration::DESCRIPTION
20
+ program :help_formatter, Commander::HelpFormatter::TerminalCompact
18
21
 
19
22
  default_command :transform
20
23
  global_option '-i', '--interactive', 'Turn on interactive Mode. In case you forgot all these super complexive args and options' do say "-- LGTM HD Interactive Mode --" end
21
24
  global_option '-d', '--dest DIR', String, 'Directory to export the LGTM image to. Default value is user\'s current working directory'
25
+ global_option '-p', '--preview QUALITY', String, 'Quality of Image preview live on terminal at the end. Accepted values for QUALITY are [high, low, none]. Default value is high. Set to none for skipping'
22
26
 
23
27
  command :random do |c|
24
28
  c.syntax = CMD_RANDOM_SYNTAX
@@ -29,6 +33,7 @@ module LgtmHD
29
33
  c.action do |args, options|
30
34
  if options.interactive # Interactive mode!
31
35
  options.dest ||= ask('Destination Directory (Enter to skip): ')
36
+ options.preview ||= ask('Image Preview Quality? [high|low|none] (Enter to skip)')
32
37
  end
33
38
  dest_dir = CLI.destination_dir(options.dest)
34
39
  dest_file_prefix = CLI.destination_file_prefix
@@ -40,11 +45,15 @@ module LgtmHD
40
45
  end
41
46
 
42
47
  say_ok "Exported image to #{dest_uri}"
48
+
49
+ show_preview dest_uri, options.preview
50
+
43
51
  copy_file_to_clipboard(dest_uri)
44
52
  say "\nOr you can copy the markdown format below provided by lgtm.in"
45
53
  say_code_block "#{image_markdown}"
46
54
  say "\nIf the image does not have LGTM texts on it, run the cmd below"
47
55
  say_code_block "lgtm_hd #{dest_uri}"
56
+
48
57
  end
49
58
  end
50
59
 
@@ -59,17 +68,19 @@ module LgtmHD
59
68
  if args.length >= 1
60
69
  source_uri = args[0]
61
70
  elsif options.interactive # Interactive mode!
62
- source_uri ||= ask(' Source Image (URL or Path/to/file): ')
71
+ source_uri ||= ask('Source Image (URL or Path/to/file): ')
63
72
  options.dest ||= ask('Destination Directory (Enter to skip): ')
73
+ options.preview ||= ask('Image Preview Quality [high|low|none] (Enter to skip): ')
64
74
  else
65
75
  # Since this is the default command so we will provide a little extra care for first-time user
66
76
  help_the_noobie
67
77
  end
68
78
 
69
79
  # Validate the inputs
80
+ source_uri = CLI.source_uri(source_uri)
70
81
  dest_dir = CLI.destination_dir(options.dest)
71
82
  check_uris(dest_dir, source_uri)
72
- dest_file = File.join(dest_dir, CLI.destination_file_prefix + File.extname(source_uri))
83
+ dest_file = File.join(dest_dir, CLI.destination_file_prefix + CLI.extname(source_uri))
73
84
 
74
85
  # Do stuff with our LGTM meme
75
86
  say_step "Reading and inspecting source at #{source_uri}"
@@ -81,7 +92,8 @@ module LgtmHD
81
92
  say_step "Exporting to file"
82
93
  meme_generator.export do |output|
83
94
  say_ok "Exported LGTM image to #{output}."
84
- copy_file_to_clipboard(dest_file)
95
+ show_preview output, options.preview
96
+ copy_file_to_clipboard output
85
97
  end # end of meme_generator.export block
86
98
  end # end of action
87
99
  end # end of command transform
@@ -90,16 +102,32 @@ module LgtmHD
90
102
  end # end run def
91
103
 
92
104
  def help_the_noobie
93
- say "To add LGTM text:"
105
+ say_step "\nTo add LGTM text to image:"
94
106
  say_code_block CLI::CMD_TRANSFORM_SYNTAX
95
- say "To fetch LGTM text:"
107
+ say_step "\nTo fetch random LGTM.IN image:"
96
108
  say_code_block CLI::CMD_RANDOM_SYNTAX
97
- say "More Help:"
109
+ say_step "\nGlobal Options:"
110
+ say_code_block CLI::OPTIONS_SYNTAX
111
+ say_step "\nMore Help:"
98
112
  say_code_block "lgtm_hd --help"
99
- say "\nVisit #{LgtmHD::Configuration::MORE_HELP_URL} for development purpose or more examples"
113
+ say_step "\nVisit #{LgtmHD::Configuration::MORE_HELP_URL} for development purpose or more examples\n"
100
114
  exit
101
115
  end
102
116
 
117
+ def show_preview(image_path, quality)
118
+ quality ||= 'high'
119
+ quality.downcase!
120
+ if quality.eql? "none" then return end
121
+ quality = 'high' unless quality.eql? 'low'
122
+
123
+ say_step "\nImage Preview"
124
+ CatpixMini::print_image image_path, {
125
+ :limit_y => 1.0,
126
+ :resolution => quality,
127
+ :center_x => false,
128
+ :center_y => true
129
+ }
130
+ end
103
131
 
104
132
  private
105
133
 
@@ -146,6 +174,15 @@ module LgtmHD
146
174
  end
147
175
  end
148
176
 
177
+ def self.source_uri(source_uri)
178
+ source_uri =~ URI::regexp ? source_uri : File.expand_path(source_uri)
179
+ end
180
+
181
+ def self.extname(source_uri)
182
+ ext = File.extname(source_uri)
183
+ ext.gsub(/\?.*/, '')
184
+ end
185
+
149
186
  def self.destination_dir(dest_dir)
150
187
  dest_dir ||= Dir.pwd
151
188
  File.expand_path(dest_dir)
@@ -7,7 +7,7 @@ module LgtmHD
7
7
  "or fetching images from LGTM.in based on user's query.\n"\
8
8
  "Finally put the image to clipboard.".freeze
9
9
  MORE_HELP_URL = "https://github.com/phradion/lgtm_hd".freeze
10
-
10
+
11
11
  # Output Image configurations
12
12
  OUTPUT_PREFIX = "lgtm_hd_".freeze
13
13
  OUTPUT_MAX_WIDTH = 500
@@ -46,7 +46,7 @@ module LgtmHD
46
46
  #
47
47
  begin
48
48
  data = uri.open('Accept' => 'application/json', redirect: false, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE)
49
- json = JSON.parse data.readlines.join("")
49
+ JSON.parse data.readlines.join("")
50
50
  rescue OpenURI::HTTPRedirect => redirect
51
51
  uri = redirect.uri # assigned from the "Location" response header
52
52
  retry if (limit -= 1) > 0
@@ -3,7 +3,7 @@ require "mini_magick"
3
3
  module LgtmHD
4
4
  class MemeGenerator
5
5
  @@caption_positions = {caption_position_top: "north center", caption_position_bottom: "south center"}
6
-
6
+
7
7
  # TODO make options list for this class
8
8
  # TODO pass BLOB data into this class instead of paths
9
9
  def initialize(input_image_uri:, output_image_uri:)
@@ -38,7 +38,6 @@ module LgtmHD
38
38
  yield @output_image_uri if block_given?
39
39
  end
40
40
 
41
-
42
41
  private
43
42
 
44
43
  def image
@@ -1,3 +1,3 @@
1
1
  module LgtmHD
2
- VERSION = "0.2.0".freeze
2
+ VERSION = "0.3.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lgtm_hd
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Huy Dinh
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-05-28 00:00:00.000000000 Z
11
+ date: 2017-05-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -84,62 +84,83 @@ dependencies:
84
84
  name: commander
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - '='
87
+ - - "~>"
88
88
  - !ruby/object:Gem::Version
89
89
  version: 4.4.3
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - '='
94
+ - - "~>"
95
95
  - !ruby/object:Gem::Version
96
96
  version: 4.4.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: catpix_mini
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.1.0
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 0.1.0
107
+ type: :runtime
108
+ prerelease: false
109
+ version_requirements: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - "~>"
112
+ - !ruby/object:Gem::Version
113
+ version: 0.1.0
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 0.1.0
97
117
  - !ruby/object:Gem::Dependency
98
118
  name: clipboard
99
119
  requirement: !ruby/object:Gem::Requirement
100
120
  requirements:
101
- - - '='
121
+ - - "~>"
102
122
  - !ruby/object:Gem::Version
103
123
  version: 1.1.1
104
124
  type: :runtime
105
125
  prerelease: false
106
126
  version_requirements: !ruby/object:Gem::Requirement
107
127
  requirements:
108
- - - '='
128
+ - - "~>"
109
129
  - !ruby/object:Gem::Version
110
130
  version: 1.1.1
111
131
  - !ruby/object:Gem::Dependency
112
132
  name: os
113
133
  requirement: !ruby/object:Gem::Requirement
114
134
  requirements:
115
- - - '='
135
+ - - "~>"
116
136
  - !ruby/object:Gem::Version
117
137
  version: 1.0.0
118
138
  type: :runtime
119
139
  prerelease: false
120
140
  version_requirements: !ruby/object:Gem::Requirement
121
141
  requirements:
122
- - - '='
142
+ - - "~>"
123
143
  - !ruby/object:Gem::Version
124
144
  version: 1.0.0
125
145
  - !ruby/object:Gem::Dependency
126
146
  name: mini_magick
127
147
  requirement: !ruby/object:Gem::Requirement
128
148
  requirements:
129
- - - '='
149
+ - - "~>"
130
150
  - !ruby/object:Gem::Version
131
151
  version: 4.7.0
132
152
  type: :runtime
133
153
  prerelease: false
134
154
  version_requirements: !ruby/object:Gem::Requirement
135
155
  requirements:
136
- - - '='
156
+ - - "~>"
137
157
  - !ruby/object:Gem::Version
138
158
  version: 4.7.0
139
159
  description: |-
140
160
  This gem is command-line tool for fetching random image from lgtm.in.
141
161
  It also provide tool to apply LGTM text based on input file/url with smart text colors and positions.
142
162
  It also support direct clipboard paste to github's comment box or Slack on MacOSX.
163
+ Live preview on terminal as well!
143
164
  email:
144
165
  - phradion@gmail.com
145
166
  executables:
@@ -150,6 +171,7 @@ files:
150
171
  - ".gitignore"
151
172
  - ".rspec"
152
173
  - ".travis.yml"
174
+ - CHANGELOG.md
153
175
  - CODE_OF_CONDUCT.md
154
176
  - Gemfile
155
177
  - LICENSE
@@ -193,5 +215,6 @@ signing_key:
193
215
  specification_version: 4
194
216
  summary: CLI tool for generating images from user input with LGTM text on it, or fetching
195
217
  images from LGTM.in based on user's query. Finally put the image to clipboard. Support
196
- direct image pasting to Github and Slack on MacOSX.
218
+ direct image pasting to Github and Slack on MacOSX. Live preview on terminal as
219
+ well!
197
220
  test_files: []