1

I have a function in a DelayedJobs-run background process on my Rails app that receives Base64 image blobs, resizes and crops them, and then saves them:

image64 = Base64.decode64(screenshot)
image = MiniMagick::Image.read(image64)
image.resize "#{image.width * 0.5}x#{image.height * 0.5}"
image.crop("#{image.width}x250") if ("#{image.height}".to_i > 250)
Base64.encode64(image.to_blob)

The addition of the .crop call, however, stops this process working my production CentOS Linux server, resulting in this error from the .to_blob call:

Errno::ENOENT: No such file or directory @ rb_sysopen - /tmp/mini_magick20170228-1709-t2rcyo
  /path/app/vendor/bundle/ruby/2.4.0/gems/mini_magick-4.6.1/lib/mini_magick/image.rb:175:in `binread'
  /path/app/vendor/bundle/ruby/2.4.0/gems/mini_magick-4.6.1/lib/mini_magick/image.rb:175:in `to_blob'

Without cropping, the function works. Running this in the foreground (i.e. in rails console) does not cause an issue.

Updating ImageMagick, ensuring /usr/bin is in PATH and sim-linking identify did not work (per this).

Any help is appreciated.

Sam
  • 1,205
  • 1
  • 21
  • 39
  • 1
    Does the accepted answer to [this question](http://stackoverflow.com/questions/10448032/unable-to-crop-image-using-mini-magick) work? – vich Mar 07 '17 at 17:48
  • @mmichael Yes -- thank you. I still don't understand the reason this would only be required when run in the background, but there you go... Thanks again! What's the proper path forward? Is this a duplicate? If you want to answer, I'll accept... – Sam Mar 08 '17 at 11:57
  • I'm glad it worked - not sure why the issue only happens in the background. I'd say your question is worth keeping as it's constructed well and perhaps someone else could figure out the reason for this only happening in the background. I'm not sure which part of the other question helped you so feel free to answer and accept your own answer (I don't need the credit, but you should reference the other question and answer). – vich Mar 08 '17 at 13:50

1 Answers1

1

Per @mmichael, this question / answer shifted the problem. Specifically, changing

image.crop("#{image.width}x250")

to

image.crop("#{image.width}x250+0+0")

allows the .to_blob to happen without issue.

If anyone can explain the issue as to why this happens when run in the background only, I'll gladly accept your answer instead.

Community
  • 1
  • 1
Sam
  • 1,205
  • 1
  • 21
  • 39