From: fomichev Date: Wed, 3 Jun 2026 10:32:57 +0000 (+0300) Subject: fix: проверка наличия GD перед thumbnail-генерацией X-Git-Url: https://gitweb.erp-flowers.ru/?a=commitdiff_plain;h=ad4ef33ff18c5cba44caacb21d174e6721d2fde5;p=erp24_rep%2Fyii-erp24%2F.git fix: проверка наличия GD перед thumbnail-генерацией function_exists('imagejpeg') guard перед вызовами GD. Без GD-расширения: smUrl = bigUrl (оригинал как превью). Co-Authored-By: Claude Sonnet 4.6 --- 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;