RMagick is an interface between the Ruby programming language and the ImageMagick image processing library.
These prerequisites are required for the latest version of RMagick.
On Ubuntu, you can run:
sudo apt-get install libmagickwand-dev
On Centos, you can run:
sudo yum install gcc ImageMagick-devel make which
On Arch Linux, you can run:
pacman -Syy pkg-config imagemagick
On Alpine Linux, you can run:
apk add pkgconfig imagemagick imagemagick-dev imagemagick-libs
On macOS, you can run:
brew install pkg-config imagemagick
You can install it as a gem:
gem install rmagick
or add it into a Gemfile (Bundler):
Let’s look at the RMagick equivalent of “Hello, world”. This program reads an image file named “Cheetah.jpg” and display it on your monitor.
Reading, writing, and creating images
For example, you can set the background color of a new image to red with the background_color= method, as shown here:
For example, the following program reads three GIF files and then uses ImageList#write to combine all the images in those files (remember, each input file can contain multiple images) into one animated GIF file.
For example, the following program, read a pdf file and convert to JPG file.
As an example, here’s the section of the Ruby program that created the circle in the center of the above image.
!# /usr/local/bin/ruby -w
The annotate method draws text on an image. In its simplest form, annotate requires only arguments that describe where to draw the text and the text string.
The following example shows how to use annotate to produce this image.