flickollage 0.0.3 → 0.0.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0bf1524178358a9af7ccece83dff0511d631733f
4
- data.tar.gz: 7b52460521ecd5ec1633f780b15c525ec9651afe
3
+ metadata.gz: bd6193362e407aafb5b2d322abeebd40963c5aed
4
+ data.tar.gz: 5d73f30c9e3557930b89379446446069892ab177
5
5
  SHA512:
6
- metadata.gz: 2acf6edde06c4bc7a5326ba2401949c1f564d9fada5236cc6f0d90ac05c963606788d564fba590bd83dd0af853a9116586747ab6796ba42187277140e40186b8
7
- data.tar.gz: 05fdea90eb41ebd282ab9c1ee32c355de1baceeab78dd93b138a35b0516cb76f62c9919de0cc9a63137aa2ada5f8fed2fd1c7eac9ad3db5d7417268c69a151a2
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)
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'flickollage'
3
- s.version = '0.0.3'
3
+ s.version = '0.0.4'
4
4
  s.date = '2017-03-05'
5
5
  s.summary = 'Flickollage Collage Generator'
6
6
  s.description = 'Flickollage is a simple command line tool for generating collages'
@@ -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
- logger.error 'Flickr configuration is not provided.'
23
- false
22
+ raise Error, 'Flickr configuration is not provided.'
24
23
  end
25
24
  end
26
25
  end
@@ -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 of the dictionatry file'
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, type: :numeric, aliases: '-n', default: 10
24
- option :rows, type: :numeric, aliases: '-r', default: 5
25
- option :cols, type: :numeric, aliases: '-c', default: 2
26
- option :width, type: :numeric, aliases: '-w', default: 200
27
- option :height, type: :numeric, aliases: '-h', default: 150
28
- option :verbose, type: :boolean, aliases: '-v'
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 dolomites annapurna` will generate a photo collage.
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
- You can provide flickr api key and shared secret using options described before
33
- or environment variables `FLICKR_API_KEY` and `FLICKR_SHARED_SECRET`.
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
- return unless Flickollage.configure_flickraw(options)
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
- logger.error(e.message)
41
- logger.debug(e.inspect)
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
@@ -20,14 +20,12 @@ module Flickollage
20
20
  crop_images(options[:width], options[:height])
21
21
  end
22
22
 
23
- def generate_collage(path = nil)
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.3
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.6.9
181
+ rubygems_version: 2.4.8
182
182
  signing_key:
183
183
  specification_version: 4
184
184
  summary: Flickollage Collage Generator