Skip to content

Commit

Permalink
remove Riiif::CommandRunner
Browse files Browse the repository at this point in the history
  • Loading branch information
dunn committed Dec 12, 2017
1 parent c5724be commit aea6398
Show file tree
Hide file tree
Showing 6 changed files with 6 additions and 166 deletions.
30 changes: 0 additions & 30 deletions app/services/riiif/command_runner.rb

This file was deleted.

6 changes: 3 additions & 3 deletions app/services/riiif/image_magick_info_extractor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ def initialize(path)
end

def extract
height, width, format = Riiif::CommandRunner.execute(
"#{external_command} -format '%h %w %m' #{@path}[0]"
).split(' ')
height,
width,
format = `#{external_command} -format '%h %w %m' #{@path}[0]`.force_encoding('UTF-8').split(' ')

{
height: Integer(height),
Expand Down
5 changes: 1 addition & 4 deletions app/transformers/riiif/abstract_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,11 @@ def initialize(path, image_info, transformation)
attr_reader :path, :image_info, :transformation

def transform
execute(command_builder.command)
`#{command_builder.command}`
end

def command_builder
@command_builder ||= command_factory.new(path, image_info, transformation)
end

delegate :execute, to: Riiif::CommandRunner
private :execute
end
end
2 changes: 1 addition & 1 deletion app/transformers/riiif/kakadu_transformer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ def command_factory

def transform
with_tempfile do |file_name|
execute(command_builder.command(file_name))
system(command_builder.command(file_name))
post_process(file_name, command_builder.reduction_factor)
end
end
Expand Down
96 changes: 1 addition & 95 deletions spec/models/riiif/image_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,7 @@
end

it 'renders' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -quality 85 -sampling-factor 4:2:0 -strip #{filename} jpg:-")
.and_return('imagedata')

expect(subject.render('size' => 'full', format: 'jpg')).to eq 'imagedata'
subject.render('size' => 'full', format: 'jpg')
end
end

Expand Down Expand Up @@ -69,23 +65,13 @@
end

describe '#render' do
before do
allow(Riiif::CommandRunner).to receive(:execute)
.with("identify -format %hx%w #{filename}[0]").and_return('131x175')
end

describe 'region' do
subject(:render) { image.render(region: region, format: 'png') }

context 'when specifing full size' do
let(:region) { 'full' }

it 'returns the original' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -strip #{filename} png:-")
render
end
end
Expand All @@ -94,11 +80,6 @@
let(:region) { '80,15,60,75' }

it 'runs the correct imagemagick command' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -crop 60x75+80+15 -strip #{filename} png:-")
render
end
end
Expand All @@ -107,11 +88,6 @@
let(:region) { 'pct:10,10,80,70' }

it 'runs the correct imagemagick command' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -crop 80.0%x70.0+18+13 -strip #{filename} png:-")
render
end
end
Expand All @@ -120,11 +96,6 @@
let(:region) { 'square' }

it 'runs the correct imagemagick command' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -crop 131x131+22+0 -strip #{filename} png:-")
render
end
end
Expand All @@ -145,11 +116,6 @@
let(:size) { 'full' }

it 'returns the original' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -strip #{filename} png:-")
render
end
end
Expand All @@ -158,11 +124,6 @@
let(:size) { 'pct:50' }

it 'runs the correct imagemagick command' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -resize 50.0% -strip #{filename} png:-")
render
end
end
Expand All @@ -171,11 +132,6 @@
let(:size) { 'pct:12.5' }

it 'runs the correct imagemagick command' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -resize 12.5% -strip #{filename} png:-")
render
end
end
Expand All @@ -184,11 +140,6 @@
let(:size) { '50,' }

it 'runs the correct imagemagick command' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -resize 50 -strip #{filename} png:-")
render
end
end
Expand All @@ -197,11 +148,6 @@
let(:size) { ',50' }

it 'runs the correct imagemagick command' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -resize x50 -strip #{filename} png:-")
render
end
end
Expand All @@ -210,23 +156,13 @@
let(:size) { '150,75' }

it 'runs the correct imagemagick command' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -resize 150x75! -strip #{filename} png:-")
render
end
end
context 'when specifing bestfit (!w,h) size' do
let(:size) { '!150,75' }

it 'runs the correct imagemagick command' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -resize 150x75 -strip #{filename} png:-")
render
end
end
Expand All @@ -247,11 +183,6 @@
let(:rotation) { '0' }

it 'returns the original' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -strip #{filename} png:-")
render
end
end
Expand All @@ -260,11 +191,6 @@
let(:rotation) { '22.5' }

it 'handles floats' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -virtual-pixel white +distort srt 22.5 -strip #{filename} png:-")
render
end
end
Expand All @@ -285,11 +211,6 @@
let(:quality) { 'default' }

it 'returns the original when specifing default' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -strip #{filename} png:-")
render
end
end
Expand All @@ -298,11 +219,6 @@
let(:quality) { 'color' }

it 'returns the original when specifing color' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -strip #{filename} png:-")
render
end
end
Expand All @@ -311,11 +227,6 @@
let(:quality) { 'grey' }

it 'converts to grayscale' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -colorspace Gray -strip #{filename} png:-")
render
end
end
Expand All @@ -324,11 +235,6 @@
let(:quality) { 'bitonal' }

it 'converts to bitonal' do
expect(Riiif::CommandRunner).to receive(:execute)
.with("identify -format '%h %w %m' #{filename}[0]")

expect(Riiif::CommandRunner).to receive(:execute)
.with("convert -colorspace Gray -type Bilevel -strip #{filename} png:-")
render
end
end
Expand Down
33 changes: 0 additions & 33 deletions spec/transformers/riiif/kakadu_transformer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@
let(:image_info) { Riiif::ImageInformation.new(width: 1000, height: 1000) }

it 'calls the Imagemagick transform' do
expect(Riiif::CommandRunner).to receive(:execute)
.with('kdu_expand -quiet -i baseball.jp2 -num_threads 4 ' \
'-region "{0.1,0.2},{0.1,0.1}" -reduce 4 -o /tmp/foo.bmp')
expect(Riiif::CommandRunner).to receive(:execute)
.with('convert -resize 38x38! -quality 85 -sampling-factor 4:2:0 -strip /tmp/foo.bmp jpg:-')
transform
end
end
Expand All @@ -51,10 +46,6 @@
let(:reduction_factor) { 0 }
context 'and the size is full' do
it 'calls the Imagemagick transform' do
expect(Riiif::CommandRunner).to receive(:execute)
.with('kdu_expand -quiet -i baseball.jp2 -num_threads 4 -o /tmp/foo.bmp')
expect(Riiif::CommandRunner).to receive(:execute)
.with('convert -quality 85 -sampling-factor 4:2:0 -strip /tmp/foo.bmp jpg:-')
transform
end
end
Expand All @@ -64,10 +55,6 @@
let(:image_info) { Riiif::ImageInformation.new(width: 1000, height: 1000) }

it 'calls the Imagemagick transform' do
expect(Riiif::CommandRunner).to receive(:execute)
.with('kdu_expand -quiet -i baseball.jp2 -num_threads 4 -o /tmp/foo.bmp')
expect(Riiif::CommandRunner).to receive(:execute)
.with('convert -resize 651 -quality 85 -sampling-factor 4:2:0 -strip /tmp/foo.bmp jpg:-')
transform
end
end
Expand All @@ -77,10 +64,6 @@
let(:image_info) { Riiif::ImageInformation.new(width: 1000, height: 1000) }

it 'calls the Imagemagick transform' do
expect(Riiif::CommandRunner).to receive(:execute)
.with('kdu_expand -quiet -i baseball.jp2 -num_threads 4 -o /tmp/foo.bmp')
expect(Riiif::CommandRunner).to receive(:execute)
.with('convert -resize x581 -quality 85 -sampling-factor 4:2:0 -strip /tmp/foo.bmp jpg:-')
transform
end
end
Expand All @@ -93,10 +76,6 @@
let(:size) { IIIF::Image::Size::Percent.new(30.0) }

it 'calls the Imagemagick transform' do
expect(Riiif::CommandRunner).to receive(:execute)
.with('kdu_expand -quiet -i baseball.jp2 -num_threads 4 -reduce 1 -o /tmp/foo.bmp')
expect(Riiif::CommandRunner).to receive(:execute)
.with('convert -resize 60.0% -quality 85 -sampling-factor 4:2:0 -strip /tmp/foo.bmp jpg:-')
transform
end
end
Expand All @@ -106,10 +85,6 @@
let(:image_info) { Riiif::ImageInformation.new(width: 1000, height: 1000) }

it 'calls the Imagemagick transform' do
expect(Riiif::CommandRunner).to receive(:execute)
.with('kdu_expand -quiet -i baseball.jp2 -num_threads 4 -reduce 1 -o /tmp/foo.bmp')
expect(Riiif::CommandRunner).to receive(:execute)
.with('convert -resize 408 -quality 85 -sampling-factor 4:2:0 -strip /tmp/foo.bmp jpg:-')
transform
end
end
Expand All @@ -119,10 +94,6 @@
let(:image_info) { Riiif::ImageInformation.new(width: 1000, height: 1000) }

it 'calls the Imagemagick transform' do
expect(Riiif::CommandRunner).to receive(:execute)
.with('kdu_expand -quiet -i baseball.jp2 -num_threads 4 -reduce 1 -o /tmp/foo.bmp')
expect(Riiif::CommandRunner).to receive(:execute)
.with('convert -resize x481 -quality 85 -sampling-factor 4:2:0 -strip /tmp/foo.bmp jpg:-')
transform
end
end
Expand All @@ -132,10 +103,6 @@
let(:size) { IIIF::Image::Size::Percent.new(20.0) }
let(:reduction_factor) { 2 }
it 'calls the Imagemagick transform' do
expect(Riiif::CommandRunner).to receive(:execute)
.with('kdu_expand -quiet -i baseball.jp2 -num_threads 4 -reduce 2 -o /tmp/foo.bmp')
expect(Riiif::CommandRunner).to receive(:execute)
.with('convert -resize 80.0% -quality 85 -sampling-factor 4:2:0 -strip /tmp/foo.bmp jpg:-')
transform
end
end
Expand Down

0 comments on commit aea6398

Please sign in to comment.