Support writing image to memory and remove RubyInline dependency