Introduce RMagick to convert existing existing image files to another format

problem

What should I do if I want to convert an existing image file to another format in an environment where R Magick is already installed?

solution

Below is sample code to convert a locally existing png file to webp format.

require 'rmagick'

image = Magick::ImageList.new('xxx.png')
image.write('xxx.webp')

Introduction of RMagick

From here, we will show you how to install R Magick.

Introducing ImageMagick

RMagick requires ImageMagick as prerequisite software. For the installation method, refer to RMagick's README.md for each environment. My environment is macOS and I have installed the package manager Homebrew, so it was very easy.

brew update
brew upgrade
brew install imagemagick

Introduction of RMagick

After installing Imagemagick, install rmagick via RubyGem. You can also refer to RMagick's README.md for this as well. By the way, I used bundler.

bundle init
vi Gemfile     #=> gem 'rmagick'Added
bundle install

By the way, the introduction of R Magick seems to have a lot of troubles, so if you have any problems, RMagick's README.md "Things that can go wrong" I think you should refer to .md).

Even in my environment, the following error occurs during bundle install.

Gem::Ext::BuildError: ERROR: Failed to build gem native extension.
ERROR: Can't install RMagick 4.1.2. Can't find pkg-config in

We were able to resolve this problem based on the "Things that can go wrong" response method.

brew install pkg-config

Environmental information

$ brew -v
Homebrew 2.5.1
Homebrew/homebrew-core (git revision a2bbe; last commit 2020-09-16)
Homebrew/homebrew-cask (git revision dfa88; last commit 2020-09-16)
$ ruby -v
ruby 2.7.1p83 (2020-03-31 revision a0c7c23c9c) [x86_64-darwin18]
$ bundle -v
Bundler version 2.1.2

Recommended Posts

Introduce RMagick to convert existing existing image files to another format
Convert ruby object to JSON format
Migrate Docker image to another server
Java-How to compare image files in binary
Convert SVG files to PNG files in Java
Introduce Kotlin to your existing Java Maven Project
Convert Java nested beans to aaa.bbb [0] .ccc format