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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 032e49d9a8602410ab24b57efc8bd3de1cd523ad41e217bd76affcca385a08aa
4
- data.tar.gz: 2ae67a08b37695662dd21af0eedc7c7449423fde11ca20cd02c2f66e00ade5f4
3
+ metadata.gz: b1d474982ff7cb978506e3b5970c0514ef031a051dcd89100b73ad9d5e95a37e
4
+ data.tar.gz: bcb17191e3464ac5e3cce8071f0d3cadbe6985a9c17ea5bbffc1abd21f9cf5a6
5
5
  SHA512:
6
- metadata.gz: 9a5499840827444cea022ef95ca205f52131084938a6417441eb73898961b726b02229d6f2e14964a77bf4fa24a537ae7b5c582fec1d7bcaf72f556e789dbd23
7
- data.tar.gz: 6f53cf3ee9a63cd4906f2f09ede862f31440e573ea0d7033ce37c50d0d661d733dc7cb355e2a137e94f6a3eeb5e91904d2c37c7059039d145722a0b976b656cd
6
+ metadata.gz: bbd6c58beb6c449cc0a1947fa51f4f933e5dcac95b22369d0e3640f09d07190c3f925063ea428b044ab31e839fb45d6ca5c2c09a25478a8db1498fa9c176e57c
7
+ data.tar.gz: 94436933d34ff613b725d15e7686a87bf0c14b80a7b95800350df596075e356656b2bada4af3b35e79ccc704f54b247350db064eb98bc4d105a75484f30d43ec
@@ -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)).round
13
- h ||= (@height * (w.to_f / @width)).round
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
- before(:all) do
5
- @test_image = ImageStub.new(175,131)
6
- end
7
- subject {Imogen::Iiif::Size.new(@test_image)}
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.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: 2024-09-07 00:00:00.000000000 Z
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: '0'
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: '0'
27
+ version: 2.3.0
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: rake
30
30
  requirement: !ruby/object:Gem::Requirement