0

Newbie Rails coder here.... spent way too much time trying to figure this one out any ideas?

The following script works on my dev machine but fails in production. After this script fails - when I check /tmp folder the "mini_magick20130627-17452-1k48fim.png" file is actually there. ImageMagick convert and resize also works as expected from the command line.

## resize screenshot
## wrapper for imagemagick
require 'mini_magick'

webthumb = MiniMagick::Image.open(thumbnail_image_path)
webthumb.crop('1024x768+0+0') # width, height, top, left
webthumb.resize('250x188') # width, height
# If you want to save this image use following
webthumb.write(thumbnail_image_path)

Errno::ENOENT in SitesController#create

No such file or directory - identify -quiet -ping /tmp/mini_magick20130627-17452-1k48fim.png

user2530431
  • 1
  • 1
  • 1

4 Answers4

1

This is another answer which works.

Edit development.rb (if that is going to run with passenger) and production.rb
add to bottom of file

  ENV['PATH'] = "/usr/local/bin:#{ENV['PATH']}"

Got it from this reference: Passenger + Carrierwave + Rails

Jerome
  • 5,583
  • 3
  • 33
  • 76
0

I'll answer my own question since someone else may see this error. This issue has to do with the way Phusion Passenger (under Apache) handles environment vars. I'm using an Apache + Phusion Passenger server here.

I resolved this issue by placing the ImageMagick path vars into my apache httpd-vhosts.conf file:

<VirtualHost *:80>
...
SetEnv LD_LIBRARY_PATH /usr/local/lib
SetEnv MAGICK_HOME /usr/local/lib/ImageMagick-6.8.6
SetEnv DYLD_LIBRARY_PATH $MAGICK_HOME/lib
SetEnv PATH $MAGICK_HOME/bin:/usr/local/bin/:$PATH
...
</virtualhost>

More info available here -

From: http://blog.phusion.nl/2008/12/16/passing-environment-variables-to-ruby-from-phusion-passenger/

But wait, I’ve already set environment variables in my /etc/bashrc or /etc/profile. Why don’t they work?

If you’ve set environment variables in your /etc/bashrc or /etc/profile, then these environment variables are made available in your shell. However, on most operating systems, Apache is not started from the shell and does not load environment variables defined in bashrc/profile, which is why setting environment variables in /etc/bashrc and /etc/profile usually has no effect on Apache (and by induction, on Passenger and Rails processes).

user2530431
  • 1
  • 1
  • 1
  • This is exactly the issue (and amount of wasted time) I've faced. Before I go and gum things up even more (!) as this is not an area I'm OK with, what path should I be using, as ImageMagick is not under usr/local/lib? As I use homebrew for installing these, it confirms `/usr/local/Cellar/imagemagick/6.8.0-10` upon installation. I'd be tempted by `SetEnv MAGICK_HOME /usr/local/Cellar/imagemagick/6.8.0-10 SetEnv DYLD_LIBRARY_PATH $MAGICK_HOME/lib` But the first and forth statements make me pause: – Jerome Jan 05 '14 at 11:22
0

You set your ImageMagick parameters in configure.xml: http://imagemagick.org/script/resources.php

The example they have doesn't include the tmp directory, but you use MAGICK_TEMPORARY_PATH for that: http://www.imagemagick.org/discourse-server/viewtopic.php?f=3&t=22311 (last post)

online_p
  • 103
  • 9
0

I was unable to set my $PATH using something like SetEnv PATH "$PATH:..., but I have found a way to make it work.

In my vhost configuration file I add /usr/local/binto $PATH (this is where image magick's binaries live), but I also specify all other $PATHs, so that it all works:

SetEnv PATH "/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin"
Paweł Gościcki
  • 9,066
  • 5
  • 70
  • 81