What is the best way to rotate material's images from Ruby?

I see. That makes sense.

By the way, I see that you can use ImageMagic as a library in many languages:

You could use a C dll library (ImageMagick – MagickWand, C API) and then use Fiddle to interface from Ruby. That will avoid the command line dialog and WScript.
Module: Fiddle (Ruby 2.5.3)

You could also look at other C image libraries - like this small header only lib: