Laravel?? ??? ??? ?? ????? ???? ??
?? ? ???????? ??? ??? ?? ???? ?????. Laravel? ??? ??? ?? ??? ???? ?? ?? ?? PHP ????????. ????? ???? ?? ?? ?????? ???? ??? ???? ?? ????? ??? ? ????.
????? ?? ?? ???? Laravel?? ??? ??? ?? ????? ???? ??? ?????.
?? ???? ???? ???? ???. ??? ???? ???? ????? ????? ?? ??? ?????:
php artisan make:middleware ImageProcessingMiddleware
??? ?? app/Http/Middleware
???? ??? ImageProcessingMiddleware.php
?? ??? ?????. ? ??? ?? handle
???? ?? ??? ?????. app/Http/Middleware
目錄下創(chuàng)建一個名為 ImageProcessingMiddleware.php
的文件。打開這個文件,并在 handle
方法中添加以下代碼:
public function handle($request, Closure $next) { $response = $next($request); // 檢查是否為圖片類型 if ($response instanceof IlluminateHttpResponse && in_array($response->headers->get('Content-Type'), ['image/jpeg', 'image/png', 'image/gif'])) { // 獲取原始圖像路徑 $path = $response->original; // 執(zhí)行圖片處理邏輯 $image = Image::make($path); $image->resize(300, null, function ($constraint) { $constraint->aspectRatio(); }); $image->save($path); } return $response; }
上述代碼做了以下事情:
- 檢查返回的響應(yīng)是否為圖片類型。
- 如果是圖片類型,則使用 Intervention Image 庫打開原始圖片。
- 執(zhí)行圖片處理邏輯,這里使用了一個簡單的示例:將圖片縮放為寬度為 300 像素,高度按比例調(diào)整。
- 將處理后的圖片保存回原始路徑。
接下來,我們需要將中間件類注冊到 Laravel 應(yīng)用程序中。打開 app/Http/Kernel.php
文件,并在 $middleware
屬性中添加以下代碼:
protected $middleware = [ // ... AppHttpMiddlewareImageProcessingMiddleware::class, ];
現(xiàn)在,我們已經(jīng)完成了中間件的準備工作。接下來,我們需要創(chuàng)建一個用于測試的路由。打開 routes/web.php
文件,并添加以下代碼:
Route::get('/image', function () { $path = public_path('images/test.jpg'); return response()->file($path); });
上述代碼創(chuàng)建了一個 /image
路由,它會返回位于 public/images/test.jpg
的測試圖片。
最后,我們需要啟動 Laravel 開發(fā)服務(wù)器來測試我們的中間件。在終端中執(zhí)行以下命令:
php artisan serve
現(xiàn)在,打開瀏覽器,并訪問 http://localhost:8000/image
。你應(yīng)該可以看到位于 public/images/test.jpg
rrreee
- ??? ??? ??? ???? ?????.
- ?? ??? ?? ?? ??? ?????? ???? ?? ??? ???.
- ??? ?? ??? ?????. ???? ??? ?? ?????. ???? ??? 300??? ???? ??? ?? ???? ?????.
- ??? ???? ?? ??? ?? ?????.
???? ???? ???? Laravel ??????? ???? ???.
app/Http/Kernel.php
??? ?? $middleware
??? ?? ??? ?????. rrreee???? ???? ??? ???????. ???? ???? ??? ???? ???. routes/web.php
??? ?? ?? ??? ?????: ??rrreee??? ??? public/? ?? ??? ???? <code>/image
??? ?????. ???/ test.jpg? ??? ???. ????????? ????? ????? ?? Laravel ?? ??? ???? ???. ????? ?? ??? ?????: ??rrreee???? ????? ?? http://localhost:8000/image
? ?????. public/images/test.jpg
? ?? ?? ???? ????? ?? ??? ?? ? ? ????. ??????: ??????? ???? Laravel?? ?? ???? ??? ??? ??? ? ????. ? ????? ???? ??? ?? Intervention Image ?????? ???? ??? ??? ???? ??? ?????. ?? ?? ??? ???? ?? ? ????? ??? ??? ? ????. ? ?? ??? ????? ??? ?? ??? ????? ??? ??? ????. ??? ??? Laravel?? ??? ??? ?? ????? ???? ??? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

Laravel ?? ??: ??? ?? ? ??? ????? ?? ?? ?? ? ???? ??? ?? ? ??? ????? ??? ?????. ??? ?? ? ?? ??? ????? ???? ??? ??? ??? ??? ?? ??? ??? ??? ?? ??? ?????. ? ????? Laravel ???? ??? ?? ? ??? ????? ??? ?? ??? ??? ???????. 1. ??? ??? ??? ?????. ??? ??? ??? ???? ?? ??? ?? ???? ? ?? ?????. ???? ??? ???? JPEG ? PNG? ?????.

Golang ??? ??: ???? ?? ????? ? ??? ??? ???? ?? ??: ??? ???? ???? ??? ??? ?? ?? ???? ???? ? ? ??? ?????. Go ????? github.com/disintegration/imaging? ?? ??? ??? ?????? ??? ? ????. ? ????? ? ?????? ???? ???? ?? ????? ? ??? ??? ???? ??? ?????. 1. ????? ?? ?? Go ????? github.com/? ???? ???.

Python? ???? ??? ???? ???? ?? ??: ??? ???? ??? ??? ??? ???? ??? ?? ??? ?????. ? ? ???? ???? ???? ?? ??? ???? ??? ?????. ???? ???? ???? ???? ???? ???? ? ????. ? ????? Python? ???? ???? ???? ???? ??? ???? ?? ?? ??? ?????. 1. ??? ??? ?? ??? ???? ??? ??? ???? ??? ??? ??? ??? ?????. ???? ??? ????? ??? ???,

Golang? ???? ???? ???? ????? ????? ?? ??: ??? ?? ???? ??? ? ???? ??? ???? ??? ??? ????? ???? ??? ??? ???? ???? ? ?? ????? ???? ?????. ? ????? Golang ??? ???? ???? ??? ? ???? ?? ??? ???? ??? ???? ?? ?? ??? ?????. ??: ? ????? ?? ??? Golang ?? ??? ???? ????? ?????. ??? ??? ???? ?? ??? ?? ??? ?? ?? ??? ???? ???? ???.

PHP? ???? ???? ??? ?? ?? ??? ??? ??? ???? ???? ????, ???? ?? ??? ???? ???? ? ???? ????? ??? ? ? ????. PHP??? GD ?????? ???? ???? ??? ? ? ????. ??? PHP? ???? ???? ??? ?? ??? ???? ?? ?? ??? ?????. GD ????? ?? ???? ?? ??? GD ?????? ???? ??? ???? ???. PHP ??? phpinfo() ??? ???? ???.

Golang? ???? ??? ??? ????? ????? ?? ?? ??? ???? ??? ? ??? ??? ?? ???? ?? ?????. ? ????? Golang? ???? ???? ??? ??? ???? ??? ?????. ??? ????? ?? ???? ?? ??? ??? ??? ?? ?????? ???? ???. ?? ??? ???? ??? ?????? ??????: goget-ugithub.com/fogleman/gggoget-ugolang.org/x/im

Vue?? ??? ?? ? ?? ??? ???? ??? ?????? Vue ????? ??? ? ? ??? ??? ??? ??? ???? ?? ??? ?? ? ?? ??? ???? ?? ??? ????. ? ????? Vue?? ??? ?? ? ?? ??? ???? ? ?? ??? ???? ?? ?? ??? ?????. 1. ??? ??? ??? ?? ??(LazyLoading)? ?????. ??? ?? ??? ??? ??? ????? ??, ? ???? ??? ??? ???? ??? ???? ???? ????. ??? ?? ???? ?? ??? ? ??? ???? ?? ??? ?????.

Golang? ???? ???? ?? ?? ? ?? ??? ???? ?? ??: ? ????? Golang ????? ??? ???? ???? ?? ?? ? ?? ??? ???? ??? ?????. ?? ?????? ???? ???? ???? ??? ?? ??? ?????. ??: ??? ??? ??? ?? ???? ??? ?? ?????. ?? ??? ?? ??? ???? ?? ? ? ?????. ? ????? ?? Golang ????? ??? ???? ? ? ?? ??? ???? ??? ?????. ?? ??: ?? ???
