Skip to content

Commit b52deaf

Browse files
authored
Merge pull request #2 from nyu-dss/enhancement/smart-compress-tifs
Enhancement/smart compress tifs
2 parents 5de7083 + cc95515 commit b52deaf

File tree

6 files changed

+12
-7
lines changed

6 files changed

+12
-7
lines changed

.rubocop.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ Style/StringLiteralsInInterpolation:
1515
EnforcedStyle: single_quotes
1616

1717
Layout/LineLength:
18-
Max: 120
18+
Max: 125
1919
AllowedPatterns:
2020
- 'raise'
2121

2222
Naming/RescuedExceptionsVariableName:
2323
Enabled: false # conflicts with reek expectations
24-
24+
Metrics/ClassLength:
25+
Enabled: false
26+
2527
Metrics/BlockLength:
2628
Exclude:
2729
- '*.gemspec'

lib/aperitiiif.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
require 'colorize'
44
require 'thor'
5+
require 'vips'
56

67
require 'aperitiiif/asset'
78
require 'aperitiiif/batch'

lib/aperitiiif/asset.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ module Aperitiiif
1111
class Asset
1212
attr_reader :parent_id
1313

14-
TARGET_EXT = '.jpg'
14+
TARGET_EXT = '.tif'
15+
TARGET_OPTS = { tile: :pyramid, compression: :jpeg, tile_width: 256, tile_height: 256 }.freeze
1516

1617
def initialize(parent_id, source, config)
1718
@parent_id = parent_id
@@ -93,7 +94,8 @@ def write_to_target
9394
return false if target_written?
9495

9596
FileUtils.mkdir_p @config.image_build_dir
96-
Vips::Image.new_from_file(@source).write_to_file target
97+
Vips::Image.new_from_file(@source).tiffsave target, **TARGET_OPTS
98+
GC.start
9799
end
98100

99101
def service

lib/aperitiiif/utils.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def self.rm_ext(str) = str.sub File.extname(str), ''
1111
def self.parent_id(str, dir) = prune_prefix_junk(rm_ext(str.sub(dir, '')))
1212
def self.parent_dir(str) = File.dirname(str).split('/').last
1313
def self.prune_prefix_junk(str) = str.sub(/^(_|\W+)/, '')
14-
def self.mime(path) = MimeMagic.by_magic(File.open(path)).to_s
14+
def self.mime(path) = MimeMagic.by_path(path).to_s
1515
def self.valid_source?(path) = File.file?(path) && path.end_with?(*ALLOWED_SRC_FORMATS)
1616

1717
def self.slugify(str)

lib/aperitiiif/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module Aperitiiif
4-
VERSION = '0.1.0'
4+
VERSION = '0.1.1'
55
end

spec/aperitiiif/asset_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050

5151
describe '.target_mime' do
5252
it 'returns tiff mime string' do
53-
expect(@asset.target_mime).to eq('image/jpeg')
53+
expect(@asset.target_mime).to eq('image/tiff')
5454
end
5555
end
5656

0 commit comments

Comments
 (0)