画像処理に便利なライブラリIntervention ImageをLaravel9に導入します。
Intervention Imageをcomposerからインストールします。
[root@ubuntu2004 ~]# composer require intervention/image
INFO Discovering packages.
danielme85/laravel-geoip2 ............................................. DONE
intervention/image .................................................... DONE
laravel/sail .......................................................... DONE
laravel/sanctum ....................................................... DONE
laravel/tinker ........................................................ DONE
nesbot/carbon ......................................................... DONE
nunomaduro/collision .................................................. DONE
nunomaduro/termwind ................................................... DONE
simplesoftwareio/simple-qrcode ........................................ DONE
spatie/laravel-ignition ............................................... DONE
82 packages you are using are looking for funding.
Use the `composer fund` command to find out more!
> @php artisan vendor:publish --tag=laravel-assets --ansi --force
INFO No publishable resources for tag [laravel-assets].
Lravelのconfig/app.phpを修正してエイリアスを登録して使いやすくします。
providersとaliasesキーにIntervention\Image\ImageServiceProvider::class、Intervention\Image\Facades\Image::classを追記
<?php
'providers' => [
/*
* Package Service Providers...
*/
Intervention\Image\ImageServiceProvider::class,
],
'aliases' => Facade::defaultAliases()->merge([
'Image' => Intervention\Image\Facades\Image::class,
])->toArray(),
ImageMagickを使うように設定します。/config/image.phpを生成します。
ImageMagick本体がインストールされていない場合はインストールしてください。
# ImageMagickインストール
apt install imagemagick
# /config/image.phpを生成
php artisan vendor:publish --provider="Intervention\Image\ImageServiceProviderLaravelRecent"
/config/image.phpのdriver箇所をgdからimagickに変更します
<?php
// 'driver' => 'gd'
'driver' => 'imagick'
■参考資料
プログラムメモ様ありがとうございます。
https://pgmemo.tokyo/data/archives/1932.html