[solved] Cfs:graphicsmagic alternative

I’ve been using cfs:graphicsmagic in an app and when it was time this morning to deploy to a testing environment (ubuntu, both 14.04 and 15.04) it failed, complaining about Cannot call method 'split' of undefined for which there is an existing bug report.

I’m kind of under some time presssure, so I’m wondering if anyone

  • has faced this and overcome it
  • found an alternative solution for backend image manipulation

I don’t want client side image manipulation, the requirements are explicit in that regard.

Have you made sure graphicsmagick is installed?

Yep, it is installed and working fine. The problem seems to be the build. A normal run works, but a build does not.

so gm.isAvailable returns true? I had the problem when switching to mupx which uses docker and where graphicsmagick was not accessible from the container.

Well, the specific error is

TypeError: Cannot call method 'split' of undefined
    at Package (packages/cfs:graphicsmagick/gm.js:14:1) 

and that line corresponds to this in gm.js

var sep = /^win/.test(process.platform) ? ';' : ':';
var binaryPaths = process.env['PATH'].split(sep);

I just started working on an alternative that uses the Jimp NPM package. It’s not super quick but as long as your images aren’t huge and you don’t have too many requests, it may be alright. Since it’s all Javascript, it should work with free *.meteor.com hosting as well. :sunglasses:

@numtel thanks it looks very promising. Although my current requirements include support for a wider range of image types, I’ll definitely give this a go. Having this functionality contained in the app without any external (*magick) dependencies sounds great!

Ok, the problem was about the app not having privileges to access environment variables.

Apparently, this is a deployment consideration in enterprise environments where you use a process manager (like pm2, forever, strongloop, passenger etc) and dedicted unix users.

One needs explicitly check the manager’s documentation and make PATH available to node.

Hi I have been facing the same issues as you mentioned.

App 44686 stdout:
App 44686 stderr: /var/www/frolic/bundle/programs/server/node_modules/fibers/future.js:245
App 44686 stderr: throw(ex);
App 44686 stderr: ^
App 44686 stderr: TypeError: Cannot read property ‘split’ of undefined
App 44686 stderr: at packages/cfs_graphicsmagick/packages/cfs_graphicsmagick.js:22:1
App 44686 stderr: at packages/cfs_graphicsmagick/packages/cfs_graphicsmagick.js:102:1
App 44686 stderr: at /var/www/frolic/bundle/programs/server/packages/cfs_graphicsmagick.js:122:4
App 44686 stderr: at /var/www/frolic/bundle/programs/server/packages/cfs_graphicsmagick.js:131:3
App 44686 stderr: at /var/www/frolic/bundle/programs/server/boot.js:242:10
App 44686 stderr: at Array.forEach (native)
App 44686 stderr: at Function..each..forEach (/var/www/frolic/bundle/programs/server/node_modules/underscore/underscore.js:79:11)
App 44686 stderr: at /var/www/frolic/bundle/programs/server/boot.js:137:5

The above error occurs on deployment server with nginx and phusion passenger. The App has dedicated user as you mentioned. How do i fix access to environment variable?

Thanks for mentioned the cause of the problem. Glad if you could give me solution

I added

passenger_env_var PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin;

to my host configuration file (where I also declare mongo url etc)

i have the PATH env set in my host configuration but still I get the error

is graphicsmagic gm executable available in that path definition?

you could also check out the phusion passenger github issue tracker. they are very responsive.