intervention/imageを使って画像のアップロード機能をつけていくとき、以下のエラーが出ました。
NotSupportedException in Driver.php line 16:
GD Library extension not available with this PHP installation.
このエラーの解決策を書いていきます。
1. GDをPHPに有効化する
gdをPHPで有効化するために
phpbrew ext install gd
でgd拡張がインストールできます。
これで、解決できることもありますが、自分の場合jpegの画像を保存しようとすると以下のエラーが出ました。
FatalErrorException in Decoder.php line 32:
Call to undefined function Intervention\Image\Gd\imagecreatefromjpeg()
そこで、次の解決策を書いていきます。
2. gd拡張をjpegを扱うオプションをつけてインストール
まず、gd拡張を一度アンインストールします。
phpbrew ext clean gd
次に、gd拡張をjpegを扱うオプションをつけてインストールします。
phpbrew ext install gd -- --with-jpeg-dir=/usr/local/Cellar/
すると、jpegの画像でも保存できるようになりました。
3. そもそもgdをPHPで有効化できない
phpbrew ext install gd
のコマンドをうつと、以下のようなエラーが出た場合...
Error: Command failed: phpize > /Users/username/.phpbrew/build/php-5.6.23/ext/gd/build.log 2>&1 returns:
まずは、/Users/username/.phpbrew/build/php-5.6.23/ext/gd
の中身を見てあげる
次に phpize
のコマンドを打つ
$ cd /Users/username/.phpbrew/build/php-5.6.23/ext/gd
$ phpize
そうすると、ターミナルに以下のように表示された。
Configuring for:
PHP Api Version: 20041225
Zend Module Api No: 20060613
Zend Extension Api No: 220060519
Cannot find autoconf. Please check your autoconf installation and the
$PHP_AUTOCONF environment variable. Then, rerun this script.
Please check your autoconf installation
と書いてあるので、
autoconfをインストールしてあげる
$ brew install autoconf
これで、 phpbrew ext install gd
のコマンドを使うことができました。