imogen 0.4.0 → 0.5.1

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: '09c425bd9ab585fa2587f09034d1fde353bf0ba992681d5ebe0631faff1b6f6d'
4
+ data.tar.gz: 828b3d38469483aa9224c2fb2268eb9dfd2bec04e42a40c577f252b01f288d6f
5
5
  SHA512:
6
- metadata.gz: 9a5499840827444cea022ef95ca205f52131084938a6417441eb73898961b726b02229d6f2e14964a77bf4fa24a537ae7b5c582fec1d7bcaf72f556e789dbd23
7
- data.tar.gz: 6f53cf3ee9a63cd4906f2f09ede862f31440e573ea0d7033ce37c50d0d661d733dc7cb355e2a137e94f6a3eeb5e91904d2c37c7059039d145722a0b976b656cd
6
+ metadata.gz: 0eff43035b35e4ecb31cb341ef8152df76b1840c43fd042fc984b6786f2bc0c9b66e64d5801f65eba0da2dd903bc28fe7506cb027f0fb27701323a6e590ff42c
7
+ data.tar.gz: e649f55749ff213fad130d66a8429340d6268d83e10a26d49d3bdfbdf08fc7c9f1894b8e9cf5422408caf1657b48c6cab12dbdc3a68b0e65ce2168277c1190cd
@@ -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
@@ -43,7 +43,8 @@ module Imogen
43
43
  raster_opts[:rotation].to_s,
44
44
  "#{raster_opts[:quality]}.#{Imogen::Iiif::FORMATS[raster_opts[:format]]}"
45
45
  )
46
- yield(img, dest_path, raster_opts['format'], Imogen::Iiif.path_to_opts(dest_path, dest_dir))
46
+
47
+ yield(img, dest_path, raster_opts[:format], Imogen::Iiif.path_to_opts(dest_path, dest_dir))
47
48
  end
48
49
 
49
50
 
@@ -114,7 +115,7 @@ module Imogen
114
115
  raster_opts[:rotation].to_s,
115
116
  "#{raster_opts[:quality]}.#{Imogen::Iiif::FORMATS[raster_opts[:format]]}"
116
117
  )
117
- yield(img, dest_path, raster_opts['format'], Imogen::Iiif.path_to_opts(dest_path, dest_dir))
118
+ yield(img, dest_path, raster_opts[:format], Imogen::Iiif.path_to_opts(dest_path, dest_dir))
118
119
 
119
120
  row += 1
120
121
  y += tile_height
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
@@ -70,7 +70,7 @@ describe Imogen::Iiif::Tiles, type: :unit do
70
70
  64 => tile64
71
71
  }.each do |tile_size, expected_tiles|
72
72
  actual = []
73
- described_class.for(@test_image, '', :jpeg, tile_size) do |img, dest_path, format, opts|
73
+ described_class.for(@test_image, '', :jpg, tile_size) do |img, dest_path, format, opts|
74
74
  actual << dest_path
75
75
  end
76
76
  expect(actual).to eql(expected_tiles)
@@ -82,6 +82,17 @@ describe Imogen::Iiif::Tiles, type: :unit do
82
82
  actual = []
83
83
  described_class.for(@test_image, '', :png, 256) do |img, dest_path, format, opts|
84
84
  actual << dest_path
85
+ expect(format).to eq(:png)
86
+ end
87
+ expect(actual).to eql(expected)
88
+ end
89
+ it 'should produce jpg when requested' do
90
+ expected = tile256
91
+ expected.uniq!
92
+ actual = []
93
+ described_class.for(@test_image, '', :jpg, 256) do |img, dest_path, format, opts|
94
+ actual << dest_path
95
+ expect(format).to eq(:jpg)
85
96
  end
86
97
  expect(actual).to eql(expected)
87
98
  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.1
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-07-20 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