When you create an image in Rmagick and save it, chances are high that your image will be way too big. The reason is that, by default, Rmagick creates uncompressed images. Try to run ‘optipng
One way to improve on this is to set the compression level in Rmagick’s write method. Here is some clunky code to do this: