Distributing ruby script with image conversion

≡放荡痞女 提交于 2019-12-11 16:49:19

问题


I would like to distribute an executable for Mac/Windows of a Ruby script that (besides other things) will be doing a conversion from/to common image formats to .xpm / X PixMap (wikipedia)

I know about the following gems that act as a wrapper around pre-installed libraries (mostly ImageMagick): RMagick, Mini magick, Image science, Magickly, Devil, Im magick, Free-image, etc.

The problem boils down to, from what I understand, the following: Imagemagick and Freeimage need to be installed on the system, not just pointed in a relative way in the script. And Ruby2Exe, Ocra, Crate don't have the functionality to distribute the library and my script, as an executable.

Is there a technical reason why I haven't yet found a gem can perform this operation without the use of an external library? What are the possible solutions to my problem?


回答1:


One possible solution:

Find a free command-line utility which can perform the conversions you need. The best would be one which doesn't require any special installation (just dropping an EXE file onto the hard drive and running it).

In your Ruby program, invoke the command-line utility using backticks. If it is not on the system path, you may have to invoke it as utility.exe rather than utility. And so that you can invoke it correctly, regardless of the current working directory, you may have to use an absolute path, generated using File.dirname(__FILE__) and File.expand_path. Or change the working directory before trying to invoke the utility.

Finally, you will just have to package that utility together with your Ocra-generated Ruby EXE.

I suggest all this because I know that trying to install RMagick on a Windows system can be incredibly painful.



来源:https://stackoverflow.com/questions/11269046/distributing-ruby-script-with-image-conversion

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!