Skip to content

Commit d60d074

Browse files
committed
src(Image): check if file exist while creating image resource
Change-Id: Iad56787e29fdc7de20a59785c6376421a96e1794
1 parent 63c2b24 commit d60d074

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/Image.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,6 +365,19 @@ public function createFromImage(string $image): GdImage|false
365365
$image = PathUtility::getAbsolutePath($image);
366366
}
367367

368+
if (!file_exists($image)) {
369+
$imageAlt1 = $_SERVER['DOCUMENT_ROOT'] . $image;
370+
$imageAlt2 = $_SERVER['DOCUMENT_ROOT'] . '/' . $image;
371+
372+
if (file_exists($imageAlt1)) {
373+
$image = $imageAlt1;
374+
} elseif (file_exists($imageAlt2)) {
375+
$image = $imageAlt2;
376+
} else {
377+
throw new \Exception('File not found: ' . $image);
378+
}
379+
}
380+
368381
$resource = imagecreatefromstring((string)file_get_contents($image));
369382
if (!$resource) {
370383
throw new \Exception('Can\'t create GD resource.');

0 commit comments

Comments
 (0)