poleica 0.9.12 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +6 -14
  2. data/.travis.yml +2 -1
  3. data/CHANGELOG.md +30 -12
  4. data/Gemfile +5 -2
  5. data/Gemfile.lock +69 -146
  6. data/README.md +22 -12
  7. data/Rakefile +2 -3
  8. data/lib/poleica/configuration.rb +1 -0
  9. data/lib/poleica/converters/coercive.rb +3 -2
  10. data/lib/poleica/converters/convertible.rb +2 -3
  11. data/lib/poleica/converters/general.rb +0 -1
  12. data/lib/poleica/converters/graphics_magick/convert_options_generator.rb +69 -0
  13. data/lib/poleica/converters/graphics_magick/graphics_magick.rb +37 -0
  14. data/lib/poleica/converters/graphics_magick/thumbnail_options_generator.rb +108 -0
  15. data/lib/poleica/converters/libre_office.rb +13 -13
  16. data/lib/poleica/converters/utils.rb +36 -19
  17. data/lib/poleica/errors.rb +1 -0
  18. data/lib/poleica/pathable.rb +2 -2
  19. data/lib/poleica/polei.rb +1 -1
  20. data/lib/poleica/types/archive.rb +1 -2
  21. data/lib/poleica/types/document.rb +17 -18
  22. data/lib/poleica/types/general.rb +0 -2
  23. data/lib/poleica/types/image.rb +2 -3
  24. data/lib/poleica/types/pdf.rb +2 -3
  25. data/lib/poleica/version.rb +2 -1
  26. data/lib/poleica.rb +6 -1
  27. data/poleica.gemspec +0 -2
  28. data/test/poleica/configuration_test.rb +4 -2
  29. data/test/poleica/converters/coercive_test.rb +5 -6
  30. data/test/poleica/converters/graphics_magick_test.rb +38 -21
  31. data/test/poleica/converters/libre_office_test.rb +7 -8
  32. data/test/poleica/converters/utils_test.rb +12 -2
  33. data/test/poleica/types/typeable_test.rb +11 -11
  34. data/test/support/files/120x70.png +0 -0
  35. data/test/support/files/30x30.png +0 -0
  36. data/test/test_helper.rb +2 -1
  37. metadata +23 -32
  38. data/lib/poleica/converters/graphics_magick.rb +0 -118
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MWJhYzFiNTA4OWRkNTIyZmQ0MDNiODc4YzVmN2I3ZDk5ODViZTE0YQ==
5
- data.tar.gz: !binary |-
6
- MWZjMGQ2OWM3OTcxZjIzN2M1NGJmNWFmM2ViZWFjZmQ2ODk4NDkyYw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- M2FhZGE2MjI4OTA2ZGI1MzViMmZhYWVkNGJlNDRlZTY3OGZmNmE4ZTNmZjE0
10
- YTNkOGM1MDYxNzdhYTE5ODVmYzkxYjViNzQ2NjQzNDJmMWRlMThkY2QzZTVm
11
- YzFmY2FkMmYxNzQ2MmFmYjQ4N2IzN2QyYzQzMjYwNzVlNmIxZjM=
12
- data.tar.gz: !binary |-
13
- ZTg0YmU3MmJjZTg5MTllMTQ5MGRhYzdhZjgwMTc5Y2VjNmRiMTQ2NTA4NWI3
14
- M2U3ODVjNzM5ODBlNWE5YjUzMjFkMzA3MjMwNDBmYWYxNmZlNzY2YmJlYzMy
15
- Nzk3M2EwMmZlMjY1Mzc4NDZlN2RhMTY1YWY2NzM1OTg4ZDdhN2E=
2
+ SHA1:
3
+ metadata.gz: 1d3b239c7ce5ff65ab699ed739529adaf38b8bae
4
+ data.tar.gz: 72bc48906b05ebe9a97ee6688ca9b3c939907c5a
5
+ SHA512:
6
+ metadata.gz: 87c1b7f335b5edee4ba8709b47be61c1947b85417b7ce6d91180e32d080bb4efa81388a96a6e177d58e5ddf5a0a9dcb77329c2fd4f3c3c70cc4e93326b6a2f9a
7
+ data.tar.gz: c434159811f12b38281c53e655938a52a6300a8ef5dd6d9c11a327391e852fdd80b0099e8593086ff01cea89f7e2abfca6ba02415883dc4e7753c1ec120773fb
data/.travis.yml CHANGED
@@ -16,8 +16,9 @@ before_script:
16
16
  - sudo make install
17
17
  - /usr/lib/libreoffice/program/soffice.bin --nologo --headless --invisible --norestore --nolockcheck --convert-to pdf test/support/files/example.doc || true
18
18
  script:
19
- - rake
19
+ - bundle exec rake
20
20
  matrix:
21
+ fast_finish: true
21
22
  allow_failures:
22
23
  - rvm: jruby-19mode
23
24
  - rvm: rbx-19mode
data/CHANGELOG.md CHANGED
@@ -1,24 +1,42 @@
1
- # Poleica 0.9.10 (6 August 2013)
1
+ ### Poleica 0.9.12 (10 September 2013)
2
+ * Add configuration for bin_paths
3
+
4
+ ### Poleica 0.9.11 (6 September 2013)
5
+ * Replace Spoon by ChildProcess and update Travis conf
6
+
7
+ ### Poleica 0.9.10 (6 August 2013)
2
8
  * Update Libreoffice path and nolog option
3
- # Poleica 0.9.9 (6 August 2013)
9
+
10
+ ### Poleica 0.9.9 (6 August 2013)
4
11
  * Add configure method to Poleica, with timeout option
5
- # Poleica 0.9.8 (5 August 2013)
12
+
13
+ ### Poleica 0.9.8 (5 August 2013)
6
14
  * Add timeout (2 mins) on LibreOffice and GraphicsMagick execution
7
- # Poleica 0.9.7 (4 August 2013)
15
+
16
+ ### Poleica 0.9.7 (4 August 2013)
8
17
  * Add an auto-orient (true by default) to GraphicsMagick
9
- # Poleica 0.9.6 (30 July 2013)
18
+
19
+ ### Poleica 0.9.6 (30 July 2013)
10
20
  * Add thumbnail option in GraphicsMagick <3
11
- # Poleica 0.9.5 (29 July 2013)
21
+
22
+ ### Poleica 0.9.5 (29 July 2013)
12
23
  * Implement force_resize option for GraphicsMagick
13
- # Poleica 0.9.4 (24 July 2013)
24
+
25
+ ### Poleica 0.9.4 (24 July 2013)
14
26
  * Add Open Office document handling
15
- # Poleica 0.9.3 (24 July 2013)
27
+
28
+ ### Poleica 0.9.3 (24 July 2013)
16
29
  * Fix Unsupported Pages and Keynote file type
17
- # Poleica 0.9.2 (23 July 2013)
30
+
31
+ ### Poleica 0.9.2 (23 July 2013)
18
32
  * Fix the coercive converter
19
- # Poleica 0.9.1 (22 July 2013)
33
+
34
+ ### Poleica 0.9.1 (22 July 2013)
20
35
  * Escape path options
21
- # Poleica 0.9.0 (19 July 2013)
36
+
37
+ ### Poleica 0.9.0 (19 July 2013)
22
38
  * Convert to pdf and png, handle file path
23
- # Poleica 0.1.0 (14 June 2013)
39
+
40
+ ### Poleica 0.1.0 (14 June 2013)
24
41
  * Just a try, working version for pngs
42
+
data/Gemfile CHANGED
@@ -4,15 +4,18 @@ source 'https://rubygems.org'
4
4
  # Specify your gem's dependencies in poleica.gemspec
5
5
  gemspec
6
6
 
7
+ platform :mri do
8
+ gem 'pry-byebug'
9
+ end
10
+
7
11
  group :test do
12
+ gem 'rake'
8
13
  gem 'minitest'
9
14
  gem 'rubocop', github: 'bbatsov/rubocop'
10
15
  gem 'coveralls', require: false
11
16
  end
12
17
 
13
18
  group :development do
14
- gem 'jazz_hands'
15
-
16
19
  # Guards
17
20
  gem 'guard-rubocop'
18
21
  gem 'guard-minitest', github: 'guard/guard-minitest'
data/Gemfile.lock CHANGED
@@ -1,18 +1,21 @@
1
1
  GIT
2
2
  remote: git://github.com/bbatsov/rubocop.git
3
- revision: 2876ed09d2751c9f0cda33733baec031a48289fa
3
+ revision: 07c5d73b050e242ce17c4ee4ee5e91fdad554a18
4
4
  specs:
5
- rubocop (0.8.2)
6
- parser (= 2.0.0.beta6)
7
- rainbow (>= 1.1.4)
5
+ rubocop (0.18.1)
6
+ json (>= 1.7.7, < 2)
7
+ parser (~> 2.1.7)
8
+ powerpack (~> 0.0.6)
9
+ rainbow (>= 1.99.1, < 3.0)
10
+ ruby-progressbar (~> 1.4)
8
11
 
9
12
  GIT
10
13
  remote: git://github.com/guard/guard-minitest.git
11
- revision: f13d0ec2a59cd11d1b400f2db62445c6092ee112
14
+ revision: b61231b06685ea0b1d480a3da11d015eb59fc7c6
12
15
  specs:
13
- guard-minitest (1.0.0.rc.3)
14
- guard (>= 1.8)
15
- minitest (>= 2.1)
16
+ guard-minitest (2.2.0)
17
+ guard (~> 2.0)
18
+ minitest (>= 3.0)
16
19
 
17
20
  PATH
18
21
  remote: .
@@ -23,160 +26,80 @@ PATH
23
26
  GEM
24
27
  remote: https://rubygems.org/
25
28
  specs:
26
- actionpack (3.2.13)
27
- activemodel (= 3.2.13)
28
- activesupport (= 3.2.13)
29
- builder (~> 3.0.0)
30
- erubis (~> 2.7.0)
31
- journey (~> 1.0.4)
32
- rack (~> 1.4.5)
33
- rack-cache (~> 1.2)
34
- rack-test (~> 0.6.1)
35
- sprockets (~> 2.2.1)
36
- activemodel (3.2.13)
37
- activesupport (= 3.2.13)
38
- builder (~> 3.0.0)
39
- activesupport (3.2.13)
40
- i18n (= 0.6.1)
41
- multi_json (~> 1.0)
42
29
  ast (1.1.0)
43
- awesome_print (1.1.0)
44
- binding_of_caller (0.7.2)
45
- debug_inspector (>= 0.0.1)
46
- builder (3.0.4)
47
- childprocess (0.3.9)
30
+ byebug (2.7.0)
31
+ columnize (~> 0.3)
32
+ debugger-linecache (~> 1.2)
33
+ celluloid (0.15.2)
34
+ timers (~> 1.1.0)
35
+ celluloid-io (0.15.0)
36
+ celluloid (>= 0.15.0)
37
+ nio4r (>= 0.5.0)
38
+ childprocess (0.5.1)
48
39
  ffi (~> 1.0, >= 1.0.11)
49
- coderay (1.0.9)
50
- colorize (0.5.8)
51
- columnize (0.3.6)
52
- coolline (0.4.2)
53
- coveralls (0.6.7)
54
- colorize
40
+ coderay (1.1.0)
41
+ columnize (0.9.0)
42
+ coveralls (0.7.0)
55
43
  multi_json (~> 1.3)
56
44
  rest-client
57
45
  simplecov (>= 0.7)
46
+ term-ansicolor
58
47
  thor
59
- debug_inspector (0.0.2)
60
- debugger (1.6.0)
61
- columnize (>= 0.3.1)
62
- debugger-linecache (~> 1.2.0)
63
- debugger-ruby_core_source (~> 1.2.1)
64
48
  debugger-linecache (1.2.0)
65
- debugger-ruby_core_source (1.2.2)
66
- diff-lcs (1.2.4)
67
- diffy (2.1.4)
68
- erubis (2.7.0)
69
- ffi (1.9.0)
49
+ docile (1.1.3)
50
+ ffi (1.9.3)
70
51
  formatador (0.2.4)
71
- grit (2.5.0)
72
- diff-lcs (~> 1.1)
73
- mime-types (~> 1.15)
74
- posix-spawn (~> 0.3.6)
75
- guard (1.8.1)
52
+ guard (2.5.1)
76
53
  formatador (>= 0.2.4)
77
- listen (>= 1.0.0)
78
- lumberjack (>= 1.0.2)
79
- pry (>= 0.9.10)
80
- thor (>= 0.14.6)
81
- guard-rubocop (0.0.4)
82
- childprocess (~> 0.3)
83
- guard (~> 1.8)
84
- rubocop (>= 0.8.2, < 0.9.0)
85
- term-ansicolor (~> 1.1)
86
- hike (1.2.3)
87
- hirb (0.7.1)
88
- i18n (0.6.1)
89
- jazz_hands (0.5.0)
90
- awesome_print (~> 1.1.0)
91
- coderay (~> 1.0.9)
92
- coolline (>= 0.4.0)
93
- hirb (~> 0.7.1)
94
- pry (~> 0.9.12)
95
- pry-debugger (~> 0.2.2)
96
- pry-doc (~> 0.4.4)
97
- pry-git (~> 0.2.3)
98
- pry-rails (~> 0.2.2)
99
- pry-remote (>= 0.1.7)
100
- pry-stack_explorer (~> 0.4.9)
101
- railties (>= 3.0, < 5.0)
102
- journey (1.0.4)
103
- json (1.8.0)
104
- listen (1.2.2)
54
+ listen (~> 2.6)
55
+ lumberjack (~> 1.0)
56
+ pry (>= 0.9.12)
57
+ thor (>= 0.18.1)
58
+ guard-rubocop (1.0.2)
59
+ guard (~> 2.0)
60
+ rubocop (~> 0.10)
61
+ json (1.8.1)
62
+ listen (2.7.0)
63
+ celluloid (>= 0.15.2)
64
+ celluloid-io (>= 0.15.0)
105
65
  rb-fsevent (>= 0.9.3)
106
66
  rb-inotify (>= 0.9)
107
- rb-kqueue (>= 0.2)
108
- lumberjack (1.0.3)
109
- method_source (0.8.1)
110
- mime-types (1.23)
111
- minitest (5.0.5)
112
- multi_json (1.7.7)
113
- parser (2.0.0.beta6)
67
+ lumberjack (1.0.4)
68
+ method_source (0.8.2)
69
+ mime-types (1.25.1)
70
+ minitest (5.3.0)
71
+ multi_json (1.9.2)
72
+ nio4r (1.0.0)
73
+ parser (2.1.7)
114
74
  ast (~> 1.1)
115
- slop (~> 3.4)
116
- posix-spawn (0.3.6)
117
- pry (0.9.12.2)
118
- coderay (~> 1.0.5)
75
+ slop (~> 3.4, >= 3.4.5)
76
+ powerpack (0.0.9)
77
+ pry (0.9.12.6)
78
+ coderay (~> 1.0)
119
79
  method_source (~> 0.8)
120
80
  slop (~> 3.4)
121
- pry-debugger (0.2.2)
122
- debugger (~> 1.3)
123
- pry (~> 0.9.10)
124
- pry-doc (0.4.6)
125
- pry (>= 0.9)
126
- yard (>= 0.8)
127
- pry-git (0.2.3)
128
- diffy
129
- grit
130
- pry (>= 0.9.8)
131
- pry-rails (0.2.2)
132
- pry (>= 0.9.10)
133
- pry-remote (0.1.7)
134
- pry (~> 0.9)
135
- slop (~> 3.0)
136
- pry-stack_explorer (0.4.9)
137
- binding_of_caller (>= 0.7)
138
- pry (~> 0.9.11)
139
- rack (1.4.5)
140
- rack-cache (1.2)
141
- rack (>= 0.4)
142
- rack-ssl (1.3.3)
143
- rack
144
- rack-test (0.6.2)
145
- rack (>= 1.0)
146
- railties (3.2.13)
147
- actionpack (= 3.2.13)
148
- activesupport (= 3.2.13)
149
- rack-ssl (~> 1.3.2)
150
- rake (>= 0.8.7)
151
- rdoc (~> 3.4)
152
- thor (>= 0.14.6, < 2.0)
153
- rainbow (1.1.4)
154
- rake (10.1.0)
155
- rb-fsevent (0.9.3)
156
- rb-inotify (0.9.0)
157
- ffi (>= 0.5.0)
158
- rb-kqueue (0.2.0)
81
+ pry-byebug (1.3.2)
82
+ byebug (~> 2.7)
83
+ pry (~> 0.9.12)
84
+ rainbow (2.0.0)
85
+ rake (10.3.0)
86
+ rb-fsevent (0.9.4)
87
+ rb-inotify (0.9.3)
159
88
  ffi (>= 0.5.0)
160
- rdoc (3.12.2)
161
- json (~> 1.4)
162
89
  rest-client (1.6.7)
163
90
  mime-types (>= 1.16)
164
- simplecov (0.7.1)
165
- multi_json (~> 1.0)
166
- simplecov-html (~> 0.7.1)
167
- simplecov-html (0.7.1)
168
- slop (3.4.5)
169
- sprockets (2.2.2)
170
- hike (~> 1.2)
171
- multi_json (~> 1.0)
172
- rack (~> 1.0)
173
- tilt (~> 1.1, != 1.3.0)
174
- term-ansicolor (1.2.2)
175
- tins (~> 0.8)
176
- thor (0.18.1)
177
- tilt (1.4.1)
178
- tins (0.8.2)
179
- yard (0.8.6.1)
91
+ ruby-progressbar (1.4.2)
92
+ simplecov (0.8.2)
93
+ docile (~> 1.1.0)
94
+ multi_json
95
+ simplecov-html (~> 0.8.0)
96
+ simplecov-html (0.8.0)
97
+ slop (3.5.0)
98
+ term-ansicolor (1.3.0)
99
+ tins (~> 1.0)
100
+ thor (0.19.1)
101
+ timers (1.1.0)
102
+ tins (1.0.0)
180
103
 
181
104
  PLATFORMS
182
105
  ruby
@@ -186,8 +109,8 @@ DEPENDENCIES
186
109
  coveralls
187
110
  guard-minitest!
188
111
  guard-rubocop
189
- jazz_hands
190
112
  minitest
191
113
  poleica!
114
+ pry-byebug
192
115
  rake
193
116
  rubocop!
data/README.md CHANGED
@@ -1,17 +1,25 @@
1
1
  # Poleica
2
- ## Poleica = Polaroid + Leica (Real Hipster)
2
+ ## Ruby conversion tool & preview creator
3
3
 
4
4
  [![Build Status](https://travis-ci.org/antoinelyset/poleica.png?branch=master)](https://travis-ci.org/antoinelyset/poleica)
5
- [![Coverage Status](https://coveralls.io/repos/antoinelyset/Poleica/badge.png)](https://coveralls.io/r/antoinelyset/Poleica)
6
- [![Code Climate](https://codeclimate.com/github/antoinelyset/Poleica.png)](https://codeclimate.com/github/antoinelyset/Poleica)
5
+ [![Coverage Status](https://coveralls.io/repos/antoinelyset/poleica/badge.png)](https://coveralls.io/r/antoinelyset/poleica)
6
+ [![Code Climate](https://codeclimate.com/github/antoinelyset/poleica.png)](https://codeclimate.com/github/antoinelyset/poleica)
7
7
  [![Gem Version](https://badge.fury.io/rb/poleica.png)](http://badge.fury.io/rb/poleica)
8
- [![Dependency Status](https://gemnasium.com/antoinelyset/Poleica.png)](https://gemnasium.com/antoinelyset/Poleica)
8
+ [![Dependency Status](https://gemnasium.com/antoinelyset/poleica.png)](https://gemnasium.com/antoinelyset/poleica)
9
9
 
10
- ## Install
10
+ ## Concept
11
+
12
+ _ -> PDF -> Image
13
+
14
+ Image -> Image
15
+
16
+ Basically it just takes some files, tries to convert it to PDF or PNG. It was modularly written, so you can improve the gem with more conversion tools (html to pdf is planned).
17
+
18
+ ## Installation
11
19
 
12
20
  __Ubuntu__ :
13
21
 
14
- Look at .travis.yml file
22
+ Look at [.travis.yml](https://github.com/antoinelyset/poleica/blob/master/.travis.yml) file
15
23
 
16
24
  __MacOS__ :
17
25
 
@@ -33,16 +41,13 @@ or in __Gemfile__ :
33
41
  gem 'poleica'
34
42
  ```
35
43
 
36
- ## Concept
37
-
38
- _ -> PDF -> Image
39
-
40
- Image -> Image
41
44
 
42
45
  ## Usage
43
46
 
44
47
  ```
45
48
  Poleica.new(file_path).to_png
49
+ Poleica.new(file_path).to_pdf
50
+ Poleica.new(file_path).to_thumbnail
46
51
  Poleica.new(file_path).to_png(width: 400, weight: 400)
47
52
  ```
48
53
 
@@ -55,6 +60,7 @@ Poleica.configure do |config|
55
60
  config.timeout = 2 # time in secs
56
61
  config.libre_office[:bin_paths][:linux] = '/usr/local/bin/gm'
57
62
  config.graphics_magick[:bin_paths][:osx] = '/Applications/OpenOffice.app/Contents/MacOS/soffice.bin'
63
+ end
58
64
  ```
59
65
 
60
66
  ## Options
@@ -62,7 +68,6 @@ Poleica.configure do |config|
62
68
  - weight : pixels number
63
69
  - width : pixels number
64
70
  - force_resize : boolean(false) (it doesnt preserve the image ratio)
65
- - thumbnail : boolean(false) (it crops the image, preserving the image ratio)
66
71
  - path : string folder or file
67
72
  - auto_orient : boolean(true) (keep the orientation extracted from EXIF)
68
73
 
@@ -89,6 +94,8 @@ Poleica.configure do |config|
89
94
 
90
95
  ## Warning
91
96
 
97
+ - If you want to disable .~lock.#{file_name}# creation in /tmp just :
98
+ ```export SAL_ENABLE_FILE_LOCKING=0```
92
99
  - Exit LibreOffice App before tests and launch
93
100
 
94
101
  ## Thanks
@@ -103,3 +110,6 @@ Poleica.configure do |config|
103
110
 
104
111
  Poleica is released under the [MIT
105
112
  License](http://www.opensource.org/licenses/MIT)
113
+
114
+ ## Trivia
115
+ Poleica = Polaroid + Leica (hipsterism)
data/Rakefile CHANGED
@@ -1,4 +1,5 @@
1
1
  require 'rake/testtask'
2
+ require 'rubocop/rake_task'
2
3
 
3
4
  Rake::TestTask.new do |t|
4
5
  t.libs.push ['lib', 'test']
@@ -6,9 +7,7 @@ Rake::TestTask.new do |t|
6
7
  t.verbose = true
7
8
  end
8
9
 
9
- task :rubocop do |t|
10
- sh 'rubocop'
11
- end
10
+ Rubocop::RakeTask.new
12
11
 
13
12
  task :default => [:test, :rubocop]
14
13
 
@@ -1,4 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
+ # Poleica namespace
2
3
  module Poleica
3
4
  # Configuration class
4
5
  class Configuration
@@ -9,10 +9,11 @@ module Poleica
9
9
  Types::All
10
10
  ]
11
11
 
12
- # TODO Think about another way of declare return types
12
+ # TODO: Think about another way of declare return types
13
13
  TYPE_RETURNED_BY_METHOD = {
14
14
  to_pdf: Types::PDF,
15
- to_png: Types::Image
15
+ to_png: Types::Image,
16
+ to_thumbnail: Types::Image
16
17
  }
17
18
 
18
19
  attr_reader :polei
@@ -2,7 +2,6 @@
2
2
  module Poleica
3
3
  # Conversion Logic, given a type it can search for compatible converters
4
4
  module Convertible
5
-
6
5
  CONVERTERS = Poleica::Converters
7
6
  .constants.map { |c| Poleica::Converters.const_get(c) } -
8
7
  [Poleica::Converters::Utils]
@@ -23,12 +22,12 @@ module Poleica
23
22
  compatible_converter = compatible_converters.find do |converter|
24
23
  converter.method_defined?(:"to_#{extension}")
25
24
  end
26
- compatible_converter ||= Converters::Coercive
25
+ compatible_converter || Converters::Coercive
27
26
  end
28
27
 
29
28
  def compatible_converters
30
29
  @compatible_converters ||=
31
- compatible_converters_by_type(self.file_type.class) <<
30
+ compatible_converters_by_type(file_type.class) <<
32
31
  Converters::General
33
32
  end
34
33
 
@@ -4,7 +4,6 @@ module Poleica
4
4
  # The General converter, it handles any file type and return null for
5
5
  # unknown conversion
6
6
  class General
7
-
8
7
  COMPATIBLE_TYPES = [
9
8
  Types::All
10
9
  ]
@@ -0,0 +1,69 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Poleica
3
+ module Converters
4
+ class GraphicsMagick
5
+ # Generate options for the GraphicsMagick to_png
6
+ # @options page [Array, Integer]
7
+ class ConvertOptionsGenerator
8
+ attr_reader :polei, :options, :output_path
9
+
10
+ def initialize(polei, options = {})
11
+ @polei = polei
12
+ @options = default_options.merge(options)
13
+ end
14
+
15
+ def generate
16
+ [
17
+ 'convert',
18
+ "#{polei.path}#{page_options}",
19
+ orient_options,
20
+ resize_options,
21
+ output_options
22
+ ].flatten
23
+ end
24
+
25
+ private
26
+
27
+ def default_options
28
+ {
29
+ height: DEFAULT_MEASURE,
30
+ width: DEFAULT_MEASURE,
31
+ force_resize: false,
32
+ auto_orient: true,
33
+ page: 0
34
+ }
35
+ end
36
+
37
+ def page_options
38
+ @page_options ||=
39
+ "#{Array(options[:page]).flatten.compact.uniq.sort}"
40
+ end
41
+
42
+ def orient_options
43
+ @orient_options ||= options[:auto_orient] ? '-auto-orient' : ''
44
+ end
45
+
46
+ def resize_options
47
+ @resize_options ||= [
48
+ '-resize',
49
+ "#{options[:width]}x#{options[:height]}" \
50
+ "#{'!' if options[:force_resize]}"
51
+ ]
52
+ end
53
+
54
+ def output_options
55
+ @output_path = if options[:path]
56
+ if File.directory?(options[:path])
57
+ name = File.basename(polei.path_with_md5(:png))
58
+ File.join(options[:path], name)
59
+ else
60
+ options[:path]
61
+ end
62
+ else
63
+ polei.path_with_md5(:png)
64
+ end
65
+ end
66
+ end # class OptionsGenerator
67
+ end # class GraphicsMagick
68
+ end # module Converters
69
+ end # module Poleica
@@ -0,0 +1,37 @@
1
+ # -*- encoding: utf-8 -*-
2
+ module Poleica
3
+ module Converters
4
+ # The GraphicsMagick converter, use the 'gm' command to convert images and
5
+ # documents
6
+ class GraphicsMagick
7
+ include Poleica::Converters::Utils
8
+
9
+ COMPATIBLE_TYPES = [
10
+ Types::Image,
11
+ Types::PDF
12
+ ]
13
+
14
+ DEFAULT_MEASURE = 612
15
+
16
+ attr_reader :polei
17
+
18
+ def initialize(polei)
19
+ @polei = polei
20
+ end
21
+
22
+ def to_png(options = {})
23
+ opts_gen = ConvertOptionsGenerator.new(polei, options)
24
+ exec_with_timeout(bin_path, opts_gen.generate)
25
+ expected_file_path = opts_gen.output_path
26
+ File.exist?(expected_file_path) ? expected_file_path : nil
27
+ end
28
+
29
+ def to_thumbnail(options = {})
30
+ opts_gen = ThumbnailOptionsGenerator.new(polei, options)
31
+ exec_with_timeout(bin_path, opts_gen.generate)
32
+ expected_file_path = opts_gen.output_path
33
+ File.exist?(expected_file_path) ? expected_file_path : nil
34
+ end
35
+ end # class GraphicsMagick
36
+ end # module Converters
37
+ end # module Poleica