Introduction:
ImageMagick is a software suite to create, edit, and compose bitmap images. It can read, convert and write images in a variety of formats (over 100) including DPX, EXR, GIF, JPEG, JPEG-2000, PDF, PhotoCD, PNG, Postscript, SVG, and TIFF. ImageMagick is used to translate, flip, mirror, rotate, scale, shear, and transform images, adjust image colors, apply various special effects, or draw text, lines, polygons, ellipses, and Bézier curves.
ImageMagick can be used in various programming languages such as C, C++, Perl, Java, PHP, Python, Ruby, and many others. In PHP, the ImageMagick library can be used through the Imagick extension. The Imagick extension is a wrapper around the ImageMagick library, providing an object-oriented API for PHP developers.
In this tutorial, we will cover how to install the Imagick extension on macOS.
Step 1: Install Homebrew
Homebrew is a package manager for macOS that makes it easy to install and manage software packages. To install Homebrew, open Terminal and run the following command:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 2: Install ImageMagick
Once Homebrew is installed, you can use it to install ImageMagick by running the following command in Terminal:
brew install imagemagick
This will download and install the ImageMagick software on your system.
And success output
==> Fetching imagemagick
==> Downloading https://ghcr.io/v2/homebrew/core/imagemagick/manifests/7.1.0-62
######################################################################## 100.0%
==> Downloading https://ghcr.io/v2/homebrew/core/imagemagick/blobs/sha256:d67bd9
==> Downloading from https://pkg-containers.githubusercontent.com/ghcr1/blobs/sh
######################################################################## 100.0%
==> Installing dependencies for imagemagick: jbig2dec, libidn, openjpeg, ghostscript, libde265, glib, shared-mime-info, x265, libheif, liblqr, jasper, libomp and libraw
==> Installing imagemagick dependency: jbig2dec
==> Pouring jbig2dec--0.19.ventura.bottle.tar.gz
🍺 /usr/local/Cellar/jbig2dec/0.19: 13 files, 373.5KB
==> Installing imagemagick dependency: libidn
==> Pouring libidn--1.41.ventura.bottle.tar.gz
🍺 /usr/local/Cellar/libidn/1.41: 73 files, 1MB
==> Installing imagemagick dependency: openjpeg
==> Pouring openjpeg--2.5.0.ventura.bottle.1.tar.gz
🍺 /usr/local/Cellar/openjpeg/2.5.0: 536 files, 13.9MB
==> Installing imagemagick dependency: ghostscript
==> Pouring ghostscript--10.0.0.ventura.bottle.tar.gz
🍺 /usr/local/Cellar/ghostscript/10.0.0: 644 files, 147.3MB
==> Installing imagemagick dependency: libde265
==> Pouring libde265--1.0.11.ventura.bottle.tar.gz
🍺 /usr/local/Cellar/libde265/1.0.11: 21 files, 1.5MB
==> Installing imagemagick dependency: glib
==> Pouring glib--2.74.5.ventura.bottle.tar.gz
🍺 /usr/local/Cellar/glib/2.74.5: 449 files, 20.7MB
==> Installing imagemagick dependency: shared-mime-info
==> Pouring shared-mime-info--2.2.ventura.bottle.tar.gz
==> /usr/local/Cellar/shared-mime-info/2.2/bin/update-mime-database /usr/local/share/mime
🍺 /usr/local/Cellar/shared-mime-info/2.2: 86 files, 4.6MB
==> Installing imagemagick dependency: x265
==> Pouring x265--3.5.ventura.bottle.1.tar.gz
🍺 /usr/local/Cellar/x265/3.5: 11 files, 35.8MB
==> Installing imagemagick dependency: libheif
==> Pouring libheif--1.15.1.ventura.bottle.tar.gz
==> /usr/local/opt/shared-mime-info/bin/update-mime-database /usr/local/share/mime
🍺 /usr/local/Cellar/libheif/1.15.1: 24 files, 2.8MB
==> Installing imagemagick dependency: liblqr
==> Pouring liblqr--0.4.2_1.ventura.bottle.2.tar.gz
🍺 /usr/local/Cellar/liblqr/0.4.2_1: 113 files, 284.2KB
==> Installing imagemagick dependency: jasper
==> Pouring jasper--4.0.0.ventura.bottle.tar.gz
🍺 /usr/local/Cellar/jasper/4.0.0: 44 files, 1.5MB
==> Installing imagemagick dependency: libomp
==> Pouring libomp--15.0.7.ventura.bottle.tar.gz
🍺 /usr/local/Cellar/libomp/15.0.7: 7 files, 1.6MB
==> Installing imagemagick dependency: libraw
==> Pouring libraw--0.21.1.ventura.bottle.tar.gz
🍺 /usr/local/Cellar/libraw/0.21.1: 73 files, 5.6MB
==> Installing imagemagick
==> Pouring imagemagick--7.1.0-62.ventura.bottle.tar.gz
🍺 /usr/local/Cellar/imagemagick/7.1.0-62: 807 files, 28.7MB
Step 3: Install the Imagick PHP Extension
Next, we need to install the Imagick PHP extension. We can do this using PECL, which is a package manager for PHP extensions. To install PECL, run the following command in Terminal:
sudo curl -L https://pear.php.net/go-pear.phar -o /usr/local/bin/go-pear.phar
sudo php /usr/local/bin/go-pear.phar
Follow the prompts to install PECL.
Once PECL is installed, we can use it to install the Imagick extension by running the following command in Terminal:
pecl install imagick
This will download and install the Imagick extension on your system.
Step 4: Enable the Imagick Extension in PHP
Once the Imagick extension is installed, we need to enable it in PHP. To do this, we need to edit the php.ini file. Open Terminal and run the following command:
sudo nano /etc/php.ini
This will open the php.ini file in the Nano text editor.
Find the line that starts with “;extension=imagick” (without quotes) and remove the semicolon (;) from the beginning of the line to uncomment it.
Save and exit the file by pressing Control-X, then Y, then Enter.
Step 5: Restart Apache Or Nginx
Finally, we need to restart the Apache web server to make the changes take effect. To do this, run the following command in Terminal:
sudo apachectl restart
#or
brew services reload nginx
brew services restart php
This will restart the Apache web server.
Conclusion:
In this tutorial, we covered how to install the Imagick extension on macOS. We installed Homebrew, ImageMagick, and the Imagick PHP extension, and we enabled the extension in PHP. With the Imagick extension installed, PHP developers can use ImageMagick to manipulate images in their PHP applications.