imogen 0.4.0 → 0.5.0
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/lib/imogen/iiif/size.rb +7 -3
- data/lib/imogen.rb +1 -1
- data/spec/unit/imogen_iiif_size_spec.rb +22 -5
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: b1d474982ff7cb978506e3b5970c0514ef031a051dcd89100b73ad9d5e95a37e
|
|
4
|
+
data.tar.gz: bcb17191e3464ac5e3cce8071f0d3cadbe6985a9c17ea5bbffc1abd21f9cf5a6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bbd6c58beb6c449cc0a1947fa51f4f933e5dcac95b22369d0e3640f09d07190c3f925063ea428b044ab31e839fb45d6ca5c2c09a25478a8db1498fa9c176e57c
|
|
7
|
+
data.tar.gz: 94436933d34ff613b725d15e7686a87bf0c14b80a7b95800350df596075e356656b2bada4af3b35e79ccc704f54b247350db064eb98bc4d105a75484f30d43ec
|
data/lib/imogen/iiif/size.rb
CHANGED
|
@@ -9,8 +9,12 @@ class Size < Transform
|
|
|
9
9
|
w = md[1] ? min(Integer(md[1]), @width) : nil
|
|
10
10
|
h = md[2] ? min(Integer(md[2]), @height) : nil
|
|
11
11
|
raise BadRequest.new("bad scale #{scale}") unless w or h
|
|
12
|
-
w ||= (@width * (h.to_f / @height))
|
|
13
|
-
h ||= (@height * (w.to_f / @width))
|
|
12
|
+
w ||= (@width * (h.to_f / @height))
|
|
13
|
+
h ||= (@height * (w.to_f / @width))
|
|
14
|
+
w = 1 if w > 0 && w < 1 # Avoid rounding very small numbers to zero
|
|
15
|
+
h = 1 if h > 0 && h < 1 # Avoid rounding very small numbers to zero
|
|
16
|
+
w = w.round
|
|
17
|
+
h = h.round
|
|
14
18
|
e = [w,h]
|
|
15
19
|
elsif md = /^pct:(\d+(\.\d+)?)/.match(scale)
|
|
16
20
|
p = Float(md[1])
|
|
@@ -42,4 +46,4 @@ class Size < Transform
|
|
|
42
46
|
end
|
|
43
47
|
end
|
|
44
48
|
end
|
|
45
|
-
end
|
|
49
|
+
end
|
data/lib/imogen.rb
CHANGED
|
@@ -6,7 +6,7 @@ module Imogen
|
|
|
6
6
|
extend FFI::Library
|
|
7
7
|
|
|
8
8
|
# Note: library_name function comes from `require 'vips'`
|
|
9
|
-
ffi_lib library_name("vips", 42)
|
|
9
|
+
ffi_lib FFI.library_name("vips", 42)
|
|
10
10
|
|
|
11
11
|
attach_function :vips_cache_get_max_mem, [], :int
|
|
12
12
|
attach_function :vips_cache_set_max_mem, [:int], :void
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
require 'imogen/iiif'
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
|
3
3
|
describe Imogen::Iiif::Size, type: :unit do
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
subject {Imogen::Iiif::Size.new(
|
|
4
|
+
let(:test_image_width) { 175 }
|
|
5
|
+
let(:test_image_height) { 131 }
|
|
6
|
+
let(:test_image) { ImageStub.new(test_image_width, test_image_height) }
|
|
7
|
+
subject {Imogen::Iiif::Size.new(test_image)}
|
|
8
|
+
|
|
8
9
|
describe "#get" do
|
|
9
10
|
describe "with scaling width" do
|
|
10
11
|
it "should calculate for a good value" do
|
|
@@ -17,6 +18,14 @@ describe Imogen::Iiif::Size, type: :unit do
|
|
|
17
18
|
expect{subject.get("0,")}.to raise_error Imogen::Iiif::BadRequest
|
|
18
19
|
expect{subject.get("-2,")}.to raise_error Imogen::Iiif::BadRequest
|
|
19
20
|
end
|
|
21
|
+
|
|
22
|
+
context "when the scaled width is a near-zero number before rounding is applied" do
|
|
23
|
+
let(:test_image_width) { 4096 }
|
|
24
|
+
let(:test_image_height) { 3 }
|
|
25
|
+
it "should round very small values to 1 (not 0)" do
|
|
26
|
+
expect(subject.get("512,")).to eql([512, 1])
|
|
27
|
+
end
|
|
28
|
+
end
|
|
20
29
|
end
|
|
21
30
|
describe "with scaling height" do
|
|
22
31
|
it "should calculate for a good value" do
|
|
@@ -30,6 +39,14 @@ describe Imogen::Iiif::Size, type: :unit do
|
|
|
30
39
|
expect{subject.get(",0")}.to raise_error Imogen::Iiif::BadRequest
|
|
31
40
|
expect{subject.get(",-2")}.to raise_error Imogen::Iiif::BadRequest
|
|
32
41
|
end
|
|
42
|
+
|
|
43
|
+
context "when the scaled height is a near-zero number before rounding is applied" do
|
|
44
|
+
let(:test_image_width) { 3 }
|
|
45
|
+
let(:test_image_height) { 4096 }
|
|
46
|
+
it "should round very small values to 1 (not 0)" do
|
|
47
|
+
expect(subject.get(",512")).to eql([1, 512])
|
|
48
|
+
end
|
|
49
|
+
end
|
|
33
50
|
end
|
|
34
51
|
describe "with scaling width and height" do
|
|
35
52
|
it "should calculate for a good value" do
|
|
@@ -62,4 +79,4 @@ describe Imogen::Iiif::Size, type: :unit do
|
|
|
62
79
|
end
|
|
63
80
|
end
|
|
64
81
|
end
|
|
65
|
-
end
|
|
82
|
+
end
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: imogen
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.5.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Ben Armintor
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2026-05-08 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: ruby-vips
|
|
@@ -17,14 +17,14 @@ dependencies:
|
|
|
17
17
|
requirements:
|
|
18
18
|
- - ">="
|
|
19
19
|
- !ruby/object:Gem::Version
|
|
20
|
-
version:
|
|
20
|
+
version: 2.3.0
|
|
21
21
|
type: :runtime
|
|
22
22
|
prerelease: false
|
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
24
|
requirements:
|
|
25
25
|
- - ">="
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
|
-
version:
|
|
27
|
+
version: 2.3.0
|
|
28
28
|
- !ruby/object:Gem::Dependency
|
|
29
29
|
name: rake
|
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|