Class "Intervention\Image\Facades\Image" not found in Laravel 9


Posted by viling on 2025-08-12

如果在laravel 9 使用 composer 安裝 intervention/image 的話
composer require intervention/image
會自動安裝版本3
不過目前大部分找到的文章大多是V2寫法

use Intervention\Image\Facades\Image;

$img = Image::make($image);
$img->resize(300, null, function ($constraint) {
    $constraint->aspectRatio();
});
$img->save('public/img.jpg');

那麼就會報錯 Class "Intervention\Image\Facades\Image" not found
要解決這個問題的話
可以選擇指定安裝v2
composer require intervention/image:^2

或是改成v3寫法
https://image.intervention.io/v3

use Intervention\Image\ImageManager;
use Intervention\Image\Drivers\Gd\Driver;

$manager = new ImageManager(new Driver());
$img = $manager->read($image);
$img->scaleDown(width: 300);
$img->save('public/img.jpg'));

最後 你可能還需要先開啟php.ini gd設定 否則會報錯
GD PHP extension must be installed to use this driver.


#Laravel #intervention #image







Related Posts

[MTR04] W0 D1 看 Lidemy 課程影片

[MTR04] W0 D1 看 Lidemy 課程影片

Single Page Application 單頁應用

Single Page Application 單頁應用

菜鳥切版3 線條

菜鳥切版3 線條


Comments