[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Osaka/Yokohama] Looking for infrastructure/server side engineers!

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Deployed by over 500 companies] AWS construction, operation, maintenance, and monitoring services

[Successor to CentOS] AlmaLinux OS server construction/migration service

[Successor to CentOS] AlmaLinux OS server construction/migration service

[For WordPress only] Cloud server “Web Speed”

[For WordPress only] Cloud server “Web Speed”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Cheap] Website security automatic diagnosis “Quick Scanner”

[Low cost] Wasabi object storage construction and operation service

[Low cost] Wasabi object storage construction and operation service

[Reservation system development] EDISONE customization development service

[Reservation system development] EDISONE customization development service

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Registration of 100 URLs is 0 yen] Website monitoring service “Appmill”

[Compatible with over 200 countries] Global eSIM “beSIM”

[Compatible with over 200 countries] Global eSIM “beSIM”

[Compatible with Chinese corporations] Chinese cloud / server construction, operation and maintenance

[Compatible with Chinese corporations] Chinese cloud / server construction, operation and maintenance

[YouTube] Beyond official channel “Biyomaru Channel”

[YouTube] Beyond official channel “Biyomaru Channel”

【画像処理ソフト】ImageMagick と Imagick インストールに関する備忘録的な何か

こんにちは。
一日一回 OOM killer システムソリューション部のかわです。

先日 Linuxマシンに、ImageMagick をインストールすることがあったんですが、
初見というのもあってこれがなかなか苦労しました。まず情報があんまり落ちてない。
落ちててもOSが違ったりバージョンが古かったり方法が全く違ったり。
パッケージ依存関係でエラーが出るたびに繧、繝。繝シ繧ク繝槭ず繝�け

これは、AlmaLinux 8 環境でうまくいった際の備忘録である。後世の誰かの役に立ちますように。

ImageMagickとImagickの違い

まず理解しておかないといけないのが、それぞれ別物だということ。(知ってる人は読み飛ばしてね)
ImageMagick は画像ファイルを編集・変換したりするためのフリーのオープンソースソフトウェア。
Imagick はPHP拡張モジュールで、PHPからImageMagick APIを使って画像ファイルを作成・編集できるもの。

なので、ImageMagick をインストールするだけだと、PHP側から動かせないので注意!(ややこしい)

環境について

AlmaLinux 8.8
Apache 2.4.37
PHP 8.1.23
PHP-FPM 8.1.23

事前準備としてremiリポジトリを入れます

dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm

ImageMagick のインストール

何も考えずに入れようとすると、必要なパッケージが存在せずこんな感じでエラーになっちゃうので、

dnf install --enablerepo=remi ImageMagick7 ImageMagick7-devel
Last metadata expiration check: 0:54:50 ago on Fri Sep 15 15:54:10 2023.
Error:
 Problem: cannot install the best candidate for the job
  - nothing provides jasper-devel(x86-64) needed by ImageMagick7-devel-1:7.1.1.15-1.el8.remi.x86_64
  - nothing provides OpenEXR-devel(x86-64) needed by ImageMagick7-devel-1:7.1.1.15-1.el8.remi.x86_64
  - nothing provides ghostscript-devel(x86-64) needed by ImageMagick7-devel-1:7.1.1.15-1.el8.remi.x86_64
  - nothing provides jbigkit-devel(x86-64) needed by ImageMagick7-devel-1:7.1.1.15-1.el8.remi.x86_64
  - nothing provides lcms2-devel(x86-64) needed by ImageMagick7-devel-1:7.1.1.15-1.el8.remi.x86_64
  - nothing provides openjpeg2-devel(x86-64) needed by ImageMagick7-devel-1:7.1.1.15-1.el8.remi.x86_64
(try to add '--skip-broken' to skip uninstallable packages or '--nobest' to use not only best candidate packages)

「PowerTools」というリポジトリを追加・有効し、

dnf config-manager --set-enabled powertools

再度試すと、依存関係含め無事インストールできました!

dnf install --enablerepo=remi ImageMagick7 ImageMagick7-devel
AlmaLinux 8 - PowerTools                                                           938 kB/s | 3.2 MB     00:03
Last metadata expiration check: 0:00:02 ago on Sat Sep 16 16:35:59 2023.
Dependencies resolved.
===================================================================================================================
 Package                                  Arch       Version                                  Repository      Size
===================================================================================================================
Installing:
 ImageMagick7                             x86_64     1:7.1.1.15-1.el8.remi                    remi           110 k
 ImageMagick7-devel                       x86_64     1:7.1.1.15-1.el8.remi                    remi           143 k
Installing dependencies:
 ImageMagick7-libs                        x86_64     1:7.1.1.15-1.el8.remi                    remi           2.5 M
 LibRaw                                   x86_64     0.19.5-3.el8                             appstream      315 k
 OpenEXR-devel                            x86_64     2.2.0-12.el8                             powertools      85 k
 OpenEXR-libs                             x86_64     2.2.0-12.el8                             appstream      671 k
 adobe-mappings-cmap                      noarch     20171205-3.el8                           appstream      2.1 M
 adobe-mappings-cmap-deprecated           noarch     20171205-3.el8                           appstream      118 k
 adobe-mappings-pdf                       noarch     20180407-1.el8                           appstream      706 k
 atk                                      x86_64     2.28.1-1.el8                             appstream      271 k
 avahi-libs                               x86_64     0.7-20.el8                               baseos          61 k
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Installing weak dependencies:
 ImageMagick7-djvu                        x86_64     1:7.1.1.15-1.el8.remi                    remi            66 k
 open-sans-fonts                          noarch     1.10-6.el8                               appstream      482 k
Enabling module streams:
 nginx                                               1.14
 php                                                 7.2

Transaction Summary
===================================================================================================================
Install  142 Packages

Total download size: 51 M
Installed size: 155 M

バージョンが表示されればインストール完了です。

magick --version

Version: ImageMagick 7.1.1-15 Q16-HDRI x86_64 21298 https://imagemagick.org
Copyright: (C) 1999 ImageMagick Studio LLC
License: https://imagemagick.org/script/license.php
Features: Cipher DPC HDRI Modules OpenMP(4.5)
Delegates (built-in): bzlib cairo djvu fftw fontconfig freetype gslib gvc heic jbig jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png ps raqm raw rsvg tiff webp wmf x xml zip zlib
Compiler: gcc (8.5)

Imagick のインストール


こちらもそのままだと依存関係エラーが出てしまうので、事前に必要なパッケージをインストールします。

dnf install --enablerepo=remi php-pear php-devel

peclコマンドが認識できることを確認します

which pecl
/usr/bin/pecl

peclでインストールします。
Please provide the prefix of ImageMagick installation」のタイミングでEnterを押下するとインストールが進みます。

pecl install imagick

downloading imagick-3.7.0.tgz ...
Starting to download imagick-3.7.0.tgz (360,138 bytes)
.........................................................................done: 360,138 bytes
33 source files, building
running: phpize
Configuring for:
PHP Api Version:         20170718
Zend Module Api No:      20170718
Zend Extension Api No:   320170718
Please provide the prefix of ImageMagick installation [autodetect] :

インストール完了時のメッセージで「You should add "extension=imagick.so" to php.ini」と指示があるので、php.ini最下部に以下を追記します。

# ↓をphp.iniに追記

[PECL]
extension=imagick.so

ApacheとPHP-FPMをリスタートします

systemctl restart httpd
systemctl restart php-fpm.service

リスタート後PHPの追加パッケージをインストールし、PHPモジュール内に表示されればok

dnf install php81-php-pecl-imagick-im7

php -m | grep imagick
imagick

おまけで以下コマンドで現状のポリシーが確認できます。

magick -list policy

Path: /etc/ImageMagick-7/policy.xml
  Policy: Undefined
    rights: None
  Policy: Delegate
    rights: None
    pattern: *
  Policy: Filter
    rights: None
    pattern: *
  Policy: Coder
    rights: None
    pattern: *
  Policy: Coder
    rights: Read Write
    pattern: {PNG,JPEG,JPG,GIF,WEBP}

Path: [built-in]
  Policy: Undefined
    rights: None

この記事がお役に立てば【 いいね 】のご協力をお願いいたします!
12
読み込み中...
12 票, 平均: 1.00 / 112
2,524
X facebook はてなブックマーク pocket
[2024.6.30 CentOS support ended] CentOS server migration solution

[2024.6.30 CentOS support ended] CentOS server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[2025.6.30 Amazon Linux 2 support ended] Amazon Linux server migration solution

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

[Osaka/Yokohama] Actively recruiting infrastructure engineers and server side engineers!

The person who wrote this article

About the author

Kawa Ken


A curious Poke○n who belongs to the System Solution Department.