flickollage 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -0
- data/flickollage.gemspec +1 -1
- data/lib/flickollage.rb +1 -2
- data/lib/flickollage/cli.rb +54 -15
- data/lib/flickollage/collage.rb +1 -3
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bd6193362e407aafb5b2d322abeebd40963c5aed
|
4
|
+
data.tar.gz: 5d73f30c9e3557930b89379446446069892ab177
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b20723e02e0fb20733e7aa7d1dfa3719c7467a1e74c3a9b82327bc50f6b676e980be31f86aafd69a54cdea07924709b020fabd906439d3679531fcc16e00685c
|
7
|
+
data.tar.gz: 5e90c6469f43cef622a815609c589deaa2a75df71e107842c7e251ff4285e27041ad262fef322fb5053c882c505552ec9c1395a0f8cf95b20385dba6d8036024
|
data/README.md
CHANGED
@@ -18,6 +18,10 @@ variables `FLICKR_API_KEY` and `FLICKR_SHARED_SECRET` or command-line options
|
|
18
18
|
|
19
19
|
## Usage
|
20
20
|
|
21
|
+
$ flickollage help generate
|
22
|
+
|
23
|
+
It will describe all available options.
|
24
|
+
|
21
25
|
$ flickollage generate -n 2 --rows=1 --cols=2 --width=300 --height=200 Berlin 'New York'
|
22
26
|
|
23
27
|
![Cities Collage](spec/fixtures/cities.png)
|
data/flickollage.gemspec
CHANGED
data/lib/flickollage.rb
CHANGED
@@ -19,8 +19,7 @@ module Flickollage
|
|
19
19
|
FlickRaw.api_key = ENV['FLICKR_API_KEY'] || options[:flickr_api_key]
|
20
20
|
FlickRaw.shared_secret = ENV['FLICKR_SHARED_SECRET'] || options[:flickr_shared_secret]
|
21
21
|
return true if FlickRaw.api_key && FlickRaw.shared_secret
|
22
|
-
|
23
|
-
false
|
22
|
+
raise Error, 'Flickr configuration is not provided.'
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
data/lib/flickollage/cli.rb
CHANGED
@@ -10,35 +10,74 @@ module Flickollage
|
|
10
10
|
desc 'generate [LIST OF WORDS]', 'Generate collage from the list of words'
|
11
11
|
option :dict,
|
12
12
|
type: :string, aliases: '-d', default: Dictionary.default_dict_path,
|
13
|
-
desc: 'Path
|
13
|
+
desc: 'Path to a dictionatry file'
|
14
14
|
option :output,
|
15
15
|
type: :string, aliases: '-o', default: 'collage.png',
|
16
16
|
desc: 'Output image file name'
|
17
17
|
option :flickr_api_key,
|
18
18
|
type: :string,
|
19
|
-
desc: 'Flickr API Key, can also be set using environment variable'
|
19
|
+
desc: 'Flickr API Key, it can also be set using environment variable'
|
20
20
|
option :flickr_shared_secret,
|
21
21
|
type: :string,
|
22
|
-
desc: 'Flickr Shared Secret, can also be set using environment variable'
|
23
|
-
option :number,
|
24
|
-
|
25
|
-
|
26
|
-
option :
|
27
|
-
|
28
|
-
|
22
|
+
desc: 'Flickr Shared Secret, it can also be set using environment variable'
|
23
|
+
option :number,
|
24
|
+
type: :numeric, aliases: '-n', default: 10,
|
25
|
+
desc: 'Number of photos to be composed into a collage'
|
26
|
+
option :rows,
|
27
|
+
type: :numeric, aliases: '-r', default: 5,
|
28
|
+
desc: 'Number of rows in a collage grid'
|
29
|
+
option :cols,
|
30
|
+
type: :numeric, aliases: '-c', default: 2,
|
31
|
+
desc: 'Number of columns in a collage grid'
|
32
|
+
option :width,
|
33
|
+
type: :numeric, aliases: '-w', default: 200,
|
34
|
+
desc: 'Width of a cell in a collage grid'
|
35
|
+
option :height,
|
36
|
+
type: :numeric, aliases: '-h', default: 150,
|
37
|
+
desc: 'Height of a cell in a collage grid'
|
38
|
+
option :verbose,
|
39
|
+
type: :boolean, aliases: '-v',
|
40
|
+
desc: 'Print debug information'
|
29
41
|
long_desc <<-LONGDESC
|
30
|
-
`flickollage generate
|
42
|
+
`flickollage generate -n 2 --rows=1 --cols=2 Berlin 'New York'` will generate
|
43
|
+
a photo collage and save it to `collage.png` file.
|
31
44
|
|
32
|
-
|
33
|
-
|
45
|
+
Flickollage accepts a list of words as argument and generates a collage grid
|
46
|
+
from top-rated images found on Flickr using the keywords provided.
|
47
|
+
|
48
|
+
You need to provide flickr api key and shared secret using options or via
|
49
|
+
environment variables `FLICKR_API_KEY` and `FLICKR_SHARED_SECRET`.
|
34
50
|
LONGDESC
|
35
51
|
def generate(*words)
|
36
52
|
Flickollage.init_logger(options)
|
37
|
-
|
53
|
+
validate_options(options)
|
54
|
+
Flickollage.configure_flickraw(options)
|
38
55
|
Flickollage::Collage.new(words, options).generate_collage
|
39
56
|
rescue Flickollage::Error => e
|
40
|
-
|
41
|
-
|
57
|
+
print_error(e)
|
58
|
+
end
|
59
|
+
|
60
|
+
no_commands do
|
61
|
+
def validate_options(options)
|
62
|
+
validate_grid_layout(options)
|
63
|
+
validate_image_size(options)
|
64
|
+
end
|
65
|
+
|
66
|
+
def validate_grid_layout(options)
|
67
|
+
return unless options[:rows] * options[:cols] != options[:number]
|
68
|
+
raise Error,
|
69
|
+
'Number of photos should be equal to the number of places in a layout (rows * cols)'
|
70
|
+
end
|
71
|
+
|
72
|
+
def validate_image_size(options)
|
73
|
+
return unless options[:width] <= 0 || options[:height] <= 0
|
74
|
+
raise Error, 'Image width and height should be greater than 0'
|
75
|
+
end
|
76
|
+
|
77
|
+
def print_error(e)
|
78
|
+
logger.error("Error: #{e.message}")
|
79
|
+
logger.debug(e.inspect)
|
80
|
+
end
|
42
81
|
end
|
43
82
|
end
|
44
83
|
end
|
data/lib/flickollage/collage.rb
CHANGED
@@ -20,14 +20,12 @@ module Flickollage
|
|
20
20
|
crop_images(options[:width], options[:height])
|
21
21
|
end
|
22
22
|
|
23
|
-
def generate_collage(path =
|
24
|
-
path ||= options[:output]
|
23
|
+
def generate_collage(path = options[:output])
|
25
24
|
MiniMagick::Tool::Montage.new do |montage|
|
26
25
|
images.each { |image| montage << image.image.path }
|
27
26
|
|
28
27
|
montage.geometry "#{options[:width]}x#{options[:height]}+0+0"
|
29
28
|
montage.tile "#{options[:cols]}x#{options[:rows]}"
|
30
|
-
montage.background 'black'
|
31
29
|
|
32
30
|
montage << path
|
33
31
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flickollage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Aleksandr Zykov
|
@@ -178,7 +178,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
178
|
version: '0'
|
179
179
|
requirements: []
|
180
180
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.
|
181
|
+
rubygems_version: 2.4.8
|
182
182
|
signing_key:
|
183
183
|
specification_version: 4
|
184
184
|
summary: Flickollage Collage Generator
|