djatoka 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/djatoka_url +11 -1
- data/lib/djatoka/common.rb +47 -24
- data/test/test_common.rb +17 -3
- metadata +12 -12
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.8
|
data/bin/djatoka_url
CHANGED
@@ -22,11 +22,13 @@ EOS
|
|
22
22
|
opt :scale, "Scale", :type => String
|
23
23
|
opt :format, 'Format', :type => String
|
24
24
|
opt :clayer, 'clayer', :type => String
|
25
|
-
opt :square, 'Squares the image by cropping'
|
26
25
|
opt :smallbox, 'Creates a 75x75 image'
|
27
26
|
opt :metadata, 'Output metadata'
|
28
27
|
opt :levels, 'Output Levels'
|
29
28
|
opt :browser, 'Set the browser to open JSON and images with', :type => String
|
29
|
+
opt :square, 'Squares the image by cropping both sides'
|
30
|
+
opt :topleftsquare, 'Squares the image by justifying to the top left'
|
31
|
+
opt :bottomrightsquare, 'Squares the image by jutifying to the bottom right'
|
30
32
|
end
|
31
33
|
|
32
34
|
resolver = Djatoka::Resolver.new(opts[:resolver])
|
@@ -44,6 +46,14 @@ if opts[:square]
|
|
44
46
|
region.square
|
45
47
|
end
|
46
48
|
|
49
|
+
if opts[:topleftsquare]
|
50
|
+
region.top_left_square
|
51
|
+
end
|
52
|
+
|
53
|
+
if opts[:bottomrightsquare]
|
54
|
+
region.bottom_right_square
|
55
|
+
end
|
56
|
+
|
47
57
|
if opts[:metadata] or opts[:levels]
|
48
58
|
metadata = resolver.metadata(opts[:rftid])
|
49
59
|
metadata.perform
|
data/lib/djatoka/common.rb
CHANGED
@@ -30,7 +30,17 @@ module Djatoka::Common
|
|
30
30
|
|
31
31
|
# public alias for #square_params. Returns self (a Djatoka::Region)
|
32
32
|
def square
|
33
|
-
square_params
|
33
|
+
square_params(:center)
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def top_left_square
|
38
|
+
square_params(:top_left)
|
39
|
+
self
|
40
|
+
end
|
41
|
+
|
42
|
+
def bottom_right_square
|
43
|
+
square_params(:bottom_right)
|
34
44
|
self
|
35
45
|
end
|
36
46
|
|
@@ -46,6 +56,10 @@ module Djatoka::Common
|
|
46
56
|
square_uri.to_s
|
47
57
|
end
|
48
58
|
|
59
|
+
# return a region as a square justified to the top-left of image.
|
60
|
+
# for a portrait image it will be justified to the top and for landscape it
|
61
|
+
# should be justified to the
|
62
|
+
|
49
63
|
# So far we figure the best level to ask for based on any scale parameter and
|
50
64
|
# try to compensate for any difference between the dwtLevels and djatoka levels
|
51
65
|
# so that we get a decent image returned.
|
@@ -74,7 +88,7 @@ module Djatoka::Common
|
|
74
88
|
# how djatoka determines levels. See the comments for the places where the code
|
75
89
|
# tries to reconcile this difference in a way that seems to work in the cases
|
76
90
|
# seen so far.
|
77
|
-
def square_params
|
91
|
+
def square_params(justify = :center)
|
78
92
|
metadata = Djatoka::Metadata.new(resolver, rft_id).perform
|
79
93
|
if metadata
|
80
94
|
orig_height = metadata.height.to_i
|
@@ -85,16 +99,7 @@ module Djatoka::Common
|
|
85
99
|
level(pick_best_level(metadata))
|
86
100
|
end
|
87
101
|
if query.level
|
88
|
-
|
89
|
-
# dwtLevels and the djatoka levels. So far the only case seen is where
|
90
|
-
# the dwtLevels are greater than the djatoka levels.
|
91
|
-
# if metadata.dwt_levels.to_i > metadata.levels.to_i
|
92
|
-
# difference = metadata.dwt_levels.to_i - metadata.levels.to_i
|
93
|
-
# good_query_level = query.level.to_i + difference
|
94
|
-
# dwtLevels in the cases seen so far almost always match the djatoka levels.
|
95
|
-
# elsif metadata.dwt_levels.to_i == metadata.levels.to_i
|
96
|
-
good_query_level = query.level.to_i
|
97
|
-
# end
|
102
|
+
good_query_level = query.level.to_i
|
98
103
|
height = metadata.all_levels[good_query_level].height
|
99
104
|
width = metadata.all_levels[good_query_level].width
|
100
105
|
else
|
@@ -105,18 +110,36 @@ module Djatoka::Common
|
|
105
110
|
# height and width are relative to the level selected and one if not already
|
106
111
|
# a square then the longest side is cropped.
|
107
112
|
if height != width
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
113
|
+
# portrait
|
114
|
+
if height > width
|
115
|
+
h = width.to_s
|
116
|
+
w = width.to_s
|
117
|
+
if justify == :center
|
118
|
+
x = '0'
|
119
|
+
y = ((orig_height - orig_width)/2).to_s
|
120
|
+
elsif justify == :top_left
|
121
|
+
x = '0'
|
122
|
+
y = '0'
|
123
|
+
elsif justify == :bottom_right
|
124
|
+
x = '0'
|
125
|
+
y = (orig_height - orig_width).to_s
|
126
|
+
end
|
127
|
+
|
128
|
+
# landscape
|
129
|
+
elsif width > height
|
130
|
+
h = height.to_s
|
131
|
+
w = height.to_s
|
132
|
+
if justify == :center
|
133
|
+
y = '0'
|
134
|
+
x = ((orig_width - orig_height)/2).to_s
|
135
|
+
elsif justify == :top_left
|
136
|
+
x = '0'
|
137
|
+
y = '0'
|
138
|
+
elsif justify == :bottom_right
|
139
|
+
y = '0'
|
140
|
+
x = (orig_width - orig_height).to_s
|
141
|
+
end
|
142
|
+
end
|
120
143
|
region([y,x,h,w])
|
121
144
|
end
|
122
145
|
end
|
data/test/test_common.rb
CHANGED
@@ -26,6 +26,12 @@ context 'A Djatoka Resolver' do
|
|
26
26
|
assert_equal '0,874,3372,3372', @region.square.query.region
|
27
27
|
assert_equal nil, @region.square.query.scale
|
28
28
|
end
|
29
|
+
should 'create a query for a left justified version of the image' do
|
30
|
+
assert_equal '0,0,3372,3372', @region.top_left_square.query.region
|
31
|
+
end
|
32
|
+
should 'create a query for a right justified version of the image' do
|
33
|
+
assert_equal '0,1750,3372,3372', @region.bottom_right_square.query.region
|
34
|
+
end
|
29
35
|
should 'return a uri for a square version of the image' do
|
30
36
|
assert_equal '0,874,3372,3372', @region.square_uri.query_values['svc.region']
|
31
37
|
assert_equal nil, @region.square_uri.query_values['svc.scale']
|
@@ -53,11 +59,17 @@ context 'A Djatoka Resolver' do
|
|
53
59
|
setup do
|
54
60
|
@region = Djatoka::Region.new(@resolver, 'info:lanl-repo/ds/b820f537-26a1-4af8-b86a-e7a4cac6187a')
|
55
61
|
end
|
56
|
-
should 'crop appropriately into a square' do
|
62
|
+
should 'crop appropriately into a centered square' do
|
57
63
|
assert_equal '513,0,4093,4093', @region.square.query.region
|
58
64
|
end
|
65
|
+
should 'crop appropriately into a top justified square' do
|
66
|
+
assert_equal '0,0,4093,4093', @region.top_left_square.query.region
|
67
|
+
end
|
68
|
+
should 'crop appropriately into bottom justified square' do
|
69
|
+
assert_equal '1027,0,4093,4093', @region.bottom_right_square.query.region
|
70
|
+
end
|
59
71
|
end
|
60
|
-
|
72
|
+
|
61
73
|
context 'an image where the dwt_levels do not match the djatoka levels' do
|
62
74
|
setup do
|
63
75
|
@region2 = Djatoka::Region.new(@resolver, 'ua023_015-006-bx0003-014-075')
|
@@ -67,7 +79,9 @@ context 'A Djatoka Resolver' do
|
|
67
79
|
assert @region2.url
|
68
80
|
end
|
69
81
|
end
|
70
|
-
|
82
|
+
|
83
|
+
|
84
|
+
|
71
85
|
end
|
72
86
|
|
73
87
|
end
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: djatoka
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 15
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 8
|
10
|
+
version: 0.0.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Jason Ronallo
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-
|
18
|
+
date: 2010-11-02 00:00:00 -04:00
|
19
19
|
default_executable: djatoka_url
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -167,13 +167,13 @@ files:
|
|
167
167
|
- lib/djatoka/region.rb
|
168
168
|
- lib/djatoka/resolver.rb
|
169
169
|
- lib/djatoka/view_helpers.rb
|
170
|
+
- test/test_common.rb
|
171
|
+
- test/test_region.rb
|
172
|
+
- test/helper.rb
|
170
173
|
- test/test_metadata.rb
|
171
|
-
- test/test_djatoka.rb
|
172
174
|
- test/test_resolver.rb
|
173
175
|
- test/test_view_helpers.rb
|
174
|
-
- test/
|
175
|
-
- test/helper.rb
|
176
|
-
- test/test_common.rb
|
176
|
+
- test/test_djatoka.rb
|
177
177
|
has_rdoc: true
|
178
178
|
homepage: http://github.com/jronallo/djatoka
|
179
179
|
licenses: []
|
@@ -209,10 +209,10 @@ signing_key:
|
|
209
209
|
specification_version: 3
|
210
210
|
summary: Djatoka image server helpers for Ruby and Rails.
|
211
211
|
test_files:
|
212
|
+
- test/test_common.rb
|
213
|
+
- test/test_region.rb
|
214
|
+
- test/helper.rb
|
212
215
|
- test/test_metadata.rb
|
213
|
-
- test/test_djatoka.rb
|
214
216
|
- test/test_resolver.rb
|
215
217
|
- test/test_view_helpers.rb
|
216
|
-
- test/
|
217
|
-
- test/helper.rb
|
218
|
-
- test/test_common.rb
|
218
|
+
- test/test_djatoka.rb
|