Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageMagickCommandFactory: only extract first layer for PDFs #113

Merged
merged 1 commit into from
Dec 14, 2017

Conversation

dunn
Copy link
Contributor

@dunn dunn commented Dec 11, 2017

@dunn
Copy link
Contributor Author

dunn commented Dec 11, 2017

Mostly for brainstorming cc @jcoyne

@coveralls
Copy link

Coverage Status

Coverage decreased (-3.2%) to 89.818% when pulling fc71e61 on dunn:flatten into 6acf20d on curationexperts:master.

@@ -51,7 +51,10 @@ def render(args)
def info
@info ||= begin
result = info_service.call(id, file)
ImageInformation.new(width: result[:width], height: result[:height])
ImageInformation.new(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd prefer we make ImageInformation have a dimensions attribute and add the format attribute. Is there a reason we can't do that?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I think I was confused by the weird override of the initialize method. Updated now though.

@dunn
Copy link
Contributor Author

dunn commented Dec 12, 2017

Getting a bunch of failures like this:

  17) Riiif::Image#render quality when bitonal is specified converts to bitonal
      Failure/Error:
        height, width, format = Riiif::CommandRunner.execute(
          "#{external_command} -format '%h %w %m' #{@path}[0]"
        ).split(' ')

      NoMethodError:
        undefined method `split' for nil:NilClass
      # ./app/services/riiif/image_magick_info_extractor.rb:15:in `extract'
      # ./app/models/riiif/file.rb:53:in `info'
      # ./app/models/riiif/image.rb:19:in `block (2 levels) in <class:Image>'
      # ./app/models/riiif/image.rb:18:in `block in <class:Image>'
      # ./app/models/riiif/image.rb:53:in `info'
      # ./app/models/riiif/image.rb:47:in `block in render'
      # ./app/models/riiif/image.rb:46:in `render'
      # ./spec/models/riiif/image_spec.rb:282:in `block (4 levels) in <top (required)>'
      # ./spec/models/riiif/image_spec.rb:332:in `block (5 levels) in <top (required)>'

There must be something buggy with the CommandRunner, because when I run the same command directly with popen3 it works fine.

@dunn dunn changed the title WIP: ImageMagickCommandFactory: only extract first layer for PDFs ImageMagickCommandFactory: only extract first layer for PDFs Dec 12, 2017
@coveralls
Copy link

Coverage Status

Coverage decreased (-2.3%) to 90.468% when pulling f7ac03e on dunn:flatten into 3584485 on curationexperts:master.

@dunn
Copy link
Contributor Author

dunn commented Dec 12, 2017

Why do we benchmark the commands, anyway?

Copy link
Collaborator

@jcoyne jcoyne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Looks great.

@jcoyne
Copy link
Collaborator

jcoyne commented Dec 12, 2017

Looks like there's a few tests to fix up.

@dunn
Copy link
Contributor Author

dunn commented Dec 12, 2017

@jcoyne yeah, that's the CommandRunner stuff that's confusing me.

@dunn
Copy link
Contributor Author

dunn commented Dec 12, 2017

If the benchmarking isn't required, we could just remove the CommandRunner entirely.

@dunn
Copy link
Contributor Author

dunn commented Dec 12, 2017

The bizarre thing is I set a byebug if out.nil? debug trigger in #execute; it's never tripped, but somehow the downstream method calling it gets a nil response.

I thought maybe a different #execute method was somehow getting called instead, but I changed everything to be explicitly Riiif::CommandRunner.execute and it still happens.

@dunn
Copy link
Contributor Author

dunn commented Dec 12, 2017

Messing around, I tried replacing #execute just with backticks and #strip and got encoding errors, but I don't know if that's indicative of anything.

E.g.:

  9) Riiif::Image happy path renders
     Failure/Error: `#{command_builder.command}`.strip

     ArgumentError:
       invalid byte sequence in UTF-8
     # ./app/transformers/riiif/abstract_transformer.rb:20:in `strip'
     # ./app/transformers/riiif/abstract_transformer.rb:20:in `transform'
     # ./app/transformers/riiif/abstract_transformer.rb:8:in `transform'
     # ./app/models/riiif/file.rb:41:in `extract'
     # ./app/models/riiif/image.rb:47:in `block in render'
     # ./app/models/riiif/image.rb:46:in `render'
     # ./spec/models/riiif/image_spec.rb:26:in `block (3 levels) in <top (required)>'

@coveralls
Copy link

Coverage Status

Coverage decreased (-2.1%) to 90.631% when pulling 7d3d71f on dunn:flatten into 3584485 on curationexperts:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.2%) to 92.509% when pulling aea6398 on dunn:flatten into 3584485 on curationexperts:master.

.and_return('imagedata')

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This no longer tests anything. Can you restore the Riiif::CommandRunner?

@@ -69,20 +65,13 @@
end

describe '#render' do
before do
allow(Riiif::CommandRunner).to receive(:execute)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the errors are a result of this line being removed.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.07%) to 92.806% when pulling feba4c4 on dunn:flatten into 3584485 on curationexperts:master.

@jcoyne
Copy link
Collaborator

jcoyne commented Dec 14, 2017

Thanks, this looks great!

@jcoyne jcoyne merged commit db122f9 into sul-dlss:master Dec 14, 2017
@dunn dunn deleted the flatten branch December 14, 2017 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants