Skip to content

Commit d41b2ea

Browse files
committed
fix(controller): replace file_get_contents with HTTP client for image requests
- Use `Http` facade with timeout for fetching images in `OgImageController` - Improve error handling by checking for response failures Fixes #233
1 parent 9538710 commit d41b2ea

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

app/Http/Controllers/OgImageController.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use GDText\Box;
99
use GDText\Color;
1010
use Illuminate\Http\Request;
11+
use Illuminate\Support\Facades\Http;
1112
use Symfony\Component\HttpFoundation\StreamedResponse;
1213

1314
class OgImageController extends Controller
@@ -169,12 +170,14 @@ protected function wasRecipeBackgroundLoaded(GdImage $canvas, Recipe $recipe): b
169170
return false;
170171
}
171172

172-
$imageContent = file_get_contents($imageUrl);
173+
$response = Http::timeout(10)->get($imageUrl);
173174

174-
if ($imageContent === false) {
175+
if ($response->failed()) {
175176
return false;
176177
}
177178

179+
$imageContent = $response->body();
180+
178181
$sourceImage = imagecreatefromstring($imageContent);
179182

180183
if ($sourceImage === false) {

0 commit comments

Comments
 (0)