From ad4ef33ff18c5cba44caacb21d174e6721d2fde5 Mon Sep 17 00:00:00 2001 From: fomichev Date: Wed, 3 Jun 2026 13:32:57 +0300 Subject: [PATCH] =?utf8?q?fix:=20=D0=BF=D1=80=D0=BE=D0=B2=D0=B5=D1=80?= =?utf8?q?=D0=BA=D0=B0=20=D0=BD=D0=B0=D0=BB=D0=B8=D1=87=D0=B8=D1=8F=20GD?= =?utf8?q?=20=D0=BF=D0=B5=D1=80=D0=B5=D0=B4=20thumbnail-=D0=B3=D0=B5=D0=BD?= =?utf8?q?=D0=B5=D1=80=D0=B0=D1=86=D0=B8=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit function_exists('imagejpeg') guard перед вызовами GD. Без GD-расширения: smUrl = bigUrl (оригинал как превью). Co-Authored-By: Claude Sonnet 4.6 --- .../CityStoreManagementController.php | 34 +++++++++---------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/erp24/controllers/CityStoreManagementController.php b/erp24/controllers/CityStoreManagementController.php index 366be78b..526becb5 100644 --- a/erp24/controllers/CityStoreManagementController.php +++ b/erp24/controllers/CityStoreManagementController.php @@ -427,30 +427,28 @@ class CityStoreManagementController extends Controller return ['success' => false, 'message' => 'Ошибка создания директории']; } - $base = 'store_' . $storeId . '_' . time(); + $base = 'store_' . $storeId . '_' . time(); $bigFile = $dir . $base . '_big.' . $ext; - $smFile = $dir . $base . '_sm.jpg'; $file->saveAs($bigFile); $urlDir = '/uploads/' . $adminId . '/' . $dateDir . '/'; $bigUrl = $urlDir . $base . '_big.' . $ext; - - // Thumbnail через нативный GD (избегаем Imagine — может не иметь libjpeg) - $srcImg = match ($ext) { - 'png' => @imagecreatefrompng($bigFile), - 'webp' => @imagecreatefromwebp($bigFile), - default => @imagecreatefromjpeg($bigFile), - }; - - if ($srcImg !== false) { - $thumb = imagescale($srcImg, 300, 200); - imagejpeg($thumb, $smFile, 85); - $smUrl = $urlDir . $base . '_sm.jpg'; - } else { - // GD не смог открыть файл — используем оригинал как превью - $smFile = $bigFile; - $smUrl = $bigUrl; + $smUrl = $bigUrl; // fallback: превью = оригинал + + // Thumbnail через GD, если расширение доступно + if (function_exists('imagejpeg') && function_exists('imagescale')) { + $srcImg = match ($ext) { + 'png' => function_exists('imagecreatefrompng') ? @imagecreatefrompng($bigFile) : false, + 'webp' => function_exists('imagecreatefromwebp') ? @imagecreatefromwebp($bigFile) : false, + default => function_exists('imagecreatefromjpeg') ? @imagecreatefromjpeg($bigFile) : false, + }; + + if ($srcImg !== false) { + $smPath = $dir . $base . '_sm.jpg'; + imagejpeg(imagescale($srcImg, 300, 200), $smPath, 85); + $smUrl = $urlDir . $base . '_sm.jpg'; + } } $store->image_big = $bigUrl; -- 2.39.5