lgtm_hd 0.1.2 → 0.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lgtm_hd.gemspec +1 -1
- data/lib/lgtm_hd.rb +5 -1
- data/lib/lgtm_hd/cli.rb +58 -23
- data/lib/lgtm_hd/configuration.rb +1 -2
- data/lib/lgtm_hd/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4cb60a766e51ba4e5afa496f4ece6c1ed2178213
|
4
|
+
data.tar.gz: 32f930d5fd406cb6fcb8530343910a6d7d796e69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e55c1aadd8ac434d1bf3223d60dcb0a53520c77996bf6b2a6797f6ebeabb1b7d10cc799cea044fed065a706ee35088c6ede16625c25c9614be943431b9dfc71a
|
7
|
+
data.tar.gz: f20e482210fa657059447b2cd52f1479be3b2bc13aee251f1b18dc4fa6e636eb59702b2edd9041124f5968cfe490b0d449bce3727542da44c3eadf4b5ab47284
|
data/lgtm_hd.gemspec
CHANGED
data/lib/lgtm_hd.rb
CHANGED
@@ -65,7 +65,7 @@ module LgtmHD
|
|
65
65
|
end
|
66
66
|
|
67
67
|
def captionFont
|
68
|
-
'' <<
|
68
|
+
'' << LgtmHD.root << Configuration::FONT_PATH
|
69
69
|
end
|
70
70
|
|
71
71
|
def captionFontSize
|
@@ -116,4 +116,8 @@ module LgtmHD
|
|
116
116
|
end
|
117
117
|
|
118
118
|
end # End of Class
|
119
|
+
|
120
|
+
def self.root
|
121
|
+
File.expand_path '../..', __FILE__
|
122
|
+
end
|
119
123
|
end # End of Module
|
data/lib/lgtm_hd/cli.rb
CHANGED
@@ -18,42 +18,77 @@ module LgtmHD
|
|
18
18
|
program :name, LgtmHD::Configuration::PROGRAM_NAME
|
19
19
|
program :version, LgtmHD::VERSION
|
20
20
|
program :description, LgtmHD::Configuration::DESCRIPTION
|
21
|
-
default_command :
|
21
|
+
default_command :transform
|
22
22
|
|
23
23
|
command :transform do |c|
|
24
24
|
c.syntax = 'lgtm_hd transform <source_uri> <output_uri> [options]'
|
25
|
-
c.summary = 'Generate a LGTM image from source_uri (local path or URL) into
|
25
|
+
c.summary = 'Generate a LGTM image from source_uri (local path or URL) into output folder'
|
26
26
|
c.description = ''
|
27
27
|
c.example '', 'lgtm_hd export http://domain.com/image.png /path/to/lgtm.png'
|
28
28
|
c.option '--clipboard', 'Copy the end result (LGTM image) to OS\'s clipboard'
|
29
|
+
c.option '--interactive', 'In case you forgot all these super complexive args and options'
|
29
30
|
|
30
31
|
c.action do |args, options|
|
31
|
-
|
32
|
-
uri = URI.parse(args[0])
|
33
|
-
tmp_file_name = Time.now.strftime('%Y-%m-%d_%H-%M-%S') << LgtmHD::Configuration::TEMP_FILE_PREFIX
|
32
|
+
to_clipboard = options.clipboard
|
34
33
|
|
35
|
-
|
34
|
+
# ARGS validation!
|
35
|
+
if args.length == 2 then
|
36
|
+
source_uri = args[0]
|
37
|
+
output_uri = args[1]
|
38
|
+
|
39
|
+
elsif options.interactive # Interactive mode!
|
40
|
+
say "-- LGTM Interactive mode --"
|
41
|
+
source_uri = ask('Source (URL or Path/to/file): ')
|
42
|
+
output_uri = ask('Output Folder (absolute path): ')
|
43
|
+
# TODO accept relative path "~/.."
|
44
|
+
to_clipboard = agree("Copy to clipboard afterward? [Y/N]")
|
45
|
+
else
|
46
|
+
raise "Too few or too many arguments provided. Need 2: source and output URIs."
|
47
|
+
end
|
48
|
+
|
49
|
+
|
50
|
+
# Validate the inputs
|
51
|
+
unless (source_uri =~ URI::regexp or File.exist?(source_uri)) then
|
52
|
+
# Part of the reason why I fucking hate #unless. No reason.
|
53
|
+
raise "Source is not proper URIs (URL or Path/to/file)"
|
54
|
+
end
|
55
|
+
|
56
|
+
unless File.exist?(output_uri) and File.directory?(output_uri) then
|
57
|
+
raise "Output is not a directory or valid path"
|
58
|
+
end
|
59
|
+
|
60
|
+
file_ext = File.extname(source_uri)
|
61
|
+
output_uri = File.join(output_uri, "" << LgtmHD::Configuration::OUTPUT_PREFIX << Time.now.strftime('%Y-%m-%d_%H-%M-%S') << file_ext)
|
62
|
+
|
63
|
+
# Do stuff with our LGTM meme
|
64
|
+
say "- Reading and inspecting source"
|
65
|
+
meme_generator = MemeGenerator.new(source_uri, output_uri)
|
66
|
+
say "- Rendering output"
|
36
67
|
meme_generator.draw
|
37
68
|
|
69
|
+
# Export and play around with the clipboard
|
70
|
+
say "- exporting to file"
|
38
71
|
meme_generator.export do |output|
|
39
72
|
say "LGTM image has been generated at #{output}."
|
40
|
-
if
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
73
|
+
if to_clipboard then
|
74
|
+
if OS.mac? then
|
75
|
+
applescript "set the clipboard to (read (POSIX file \"#{output}\") as GIF picture)"
|
76
|
+
say "I see you are using MacOSX. Content of the file has been copied to your clipboard."
|
77
|
+
|
78
|
+
# Apple Script Command reference
|
79
|
+
# Sample: `osascript -e 'set the clipboard to (read (POSIX file "#{output}") as JPEG picture)'`
|
80
|
+
#
|
81
|
+
# Currently Github allow pasting image directly to comment box.
|
82
|
+
# However it does not support pure text content produced by pbcopy so we have to use direct Applescript
|
83
|
+
# No Universal solution as for now.
|
84
|
+
#
|
85
|
+
# Apple Script reference: http://www.macosxautomation.com/applescript/imageevents/08.html
|
86
|
+
else
|
87
|
+
Clipboard.copy(output)
|
88
|
+
say "Path to LGTM file has been copied to your clipboard."
|
89
|
+
end
|
90
|
+
end # end of if to_clipboard
|
91
|
+
end # end of meme_generator.export block
|
57
92
|
|
58
93
|
end
|
59
94
|
|
@@ -4,9 +4,8 @@ module LgtmHD
|
|
4
4
|
PROGRAM_NAME = "lgtm_hd"
|
5
5
|
DESCRIPTION = "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."
|
6
6
|
|
7
|
-
TEMP_FILE_PREFIX = "lgtm_tmp_"
|
8
|
-
|
9
7
|
# Output Image configurations
|
8
|
+
OUTPUT_PREFIX = "lgtm_tmp_"
|
10
9
|
OUTPUT_MAX_WIDTH = 500
|
11
10
|
OUTPUT_MAX_HEIGHT = 500
|
12
11
|
OUTPUT_DENSITY = 90 # or 120 point per inch
|
data/lib/lgtm_hd/version.rb
CHANGED