PHPBrewでgd拡張インストール

1. 環境

インストールする環境はこんな感じ

$ sw_vers
ProductName:	macOS
ProductVersion:	11.3
BuildVersion:	20E232

$ phpbrew --version
phpbrew - 1.27.0
cliframework core: 2.5.4

$ phpbrew list
* php-7.4.13
  php-7.3.25

$ php -v
PHP 7.4.13 (cli) (built: Dec  4 2020 21:48:53) ( NTS )
Copyright (c) The PHP Group
Zend Engine v3.4.0, Copyright (c) Zend Technologies

2. インストール

$ phpbrew ext install gd
===> Installing gd extension...
Log stored at: /Users/YOUR_USER_NAME/.phpbrew/build/php-7.4.13/ext/gd/build.log
Changing directory to /Users/YOUR_USER_NAME/.phpbrew/build/php-7.4.13/ext/gd
===> Phpize...
===> Configuring...
===> Building...
===> Running make all: /usr/bin/make -C '/Users/YOUR_USER_NAME/.phpbrew/build/php-7.4.13/ext/gd' 'all'  >> '/Users/YOUR_USER_NAME/.phpbrew/build/php-7.4.13/ext/gd/build.log' 2>&1
===> Installing...
===> Running make install: /usr/bin/make -C '/Users/YOUR_USER_NAME/.phpbrew/build/php-7.4.13/ext/gd' 'install'  >> '/Users/YOUR_USER_NAME/.phpbrew/build/php-7.4.13/ext/gd/build.log' 2>&1
===> Extension is installed.
===> Creating config file /Users/YOUR_USER_NAME/.phpbrew/php/php-7.4.13/var/db/gd.ini.disabled
===> Enabling extension gd
[*] gd extension is enabled.
Done.
$ phpbrew ext |grep gd
 [*] gd           7.4.13

3. JPEG等のサポートされる画像フォーマットを追加する

上記の方法では下記の様にJPEGサポートなどが有効にならない。

$ php -i|grep -A 10 GD
GD Support => enabled
GD Version => bundled (2.1.0 compatible)
GIF Read Support => enabled
GIF Create Support => enabled
PNG Support => enabled
libPNG Version => 1.6.37
WBMP Support => enabled
XBM Support => enabled

Directive => Local Value => Master Value
gd.jpeg_ignore_warning => 1 => 1

jpeg, webp, freetype2 をサポートするようにオプションを追加してインストールする。

$ phpbrew ext install gd -- --with-jpeg=$(brew --prefix libjpeg) --with-freetype=$(brew --prefix freetype2) --with-webp=$(brew --prefix webp)
[ ] gd extension is disabled.
===> Installing gd extension...
Log stored at: /Users/YOUR_USER_NAME/.phpbrew/build/php-7.4.13/ext/gd/build.log
Changing directory to /Users/YOUR_USER_NAME/.phpbrew/build/php-7.4.13/ext/gd
===> Running make clean: /usr/bin/make -C '/Users/YOUR_USER_NAME/.phpbrew/build/php-7.4.13/ext/gd' --quiet 'clean'
===> Phpize...
===> Configuring...
===> Building...
===> Running make all: /usr/bin/make -C '/Users/YOUR_USER_NAME/.phpbrew/build/php-7.4.13/ext/gd' 'all'  >> '/Users/YOUR_USER_NAME/.phpbrew/build/php-7.4.13/ext/gd/build.log' 2>&1
===> Installing...
===> Running make install: /usr/bin/make -C '/Users/YOUR_USER_NAME/.phpbrew/build/php-7.4.13/ext/gd' 'install'  >> '/Users/YOUR_USER_NAME/.phpbrew/build/php-7.4.13/ext/gd/build.log' 2>&1
===> Extension is installed.
===> Creating config file /Users/YOUR_USER_NAME/.phpbrew/php/php-7.4.13/var/db/gd.ini.disabled
===> Enabling extension gd
[*] gd extension is enabled.
Done.
$ php -i|grep -A 15 GD
GD Support => enabled
GD Version => bundled (2.1.0 compatible)
FreeType Support => enabled
FreeType Linkage => with freetype
FreeType Version => 2.10.4
GIF Read Support => enabled
GIF Create Support => enabled
JPEG Support => enabled
libJPEG Version => 9 compatible
PNG Support => enabled
libPNG Version => 1.6.37
WBMP Support => enabled
XBM Support => enabled
WebP Support => enabled
BMP Support => enabled
TGA Read Support => enabled

PHP7.4.0以降では、オプションが変更されている

  • --with-jpeg-dir--with-jpeg

  • --with-webp-dir--with-webp

  • --with-freetype-dir--with-freetype など

libjpeg, freetype2, webp はインストール済

$ brew install libjpeg
$ brew install freetype2
$ brew install webp

4. iniの場所

$ head ~/.phpbrew/php/php-7.4.13/var/db/gd.ini
extension=gd.so