Skip to content

Commit 6293240

Browse files
committed
Catch exception on product image generation to avoid process stopping on resize error
1 parent 5628e9b commit 6293240

File tree

1 file changed

+19
-10
lines changed

1 file changed

+19
-10
lines changed

src/Commands/Image/ImageGenerateAbstract.php

+19-10
Original file line numberDiff line numberDiff line change
@@ -302,22 +302,31 @@ protected function regenerateNewImages(string $dir, array $type, bool $productsI
302302
if (file_exists($existing_img) && filesize($existing_img)) {
303303
foreach ($type as $imageType) {
304304
if (!file_exists($dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg')) {
305-
if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg', (int) $imageType['width'], (int) $imageType['height'])) {
306-
$this->errors[] = sprintf(
307-
'Original image is corrupt %s for product ID %s or bad permission on folder.',
308-
$existing_img,
309-
(int) $imageObj->id_product
310-
);
311-
}
312-
313-
if ($generate_hight_dpi_images) {
314-
if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '2x.jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2)) {
305+
try {
306+
if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg', (int) $imageType['width'], (int) $imageType['height'])) {
315307
$this->errors[] = sprintf(
316308
'Original image is corrupt %s for product ID %s or bad permission on folder.',
317309
$existing_img,
318310
(int) $imageObj->id_product
319311
);
320312
}
313+
314+
if ($generate_hight_dpi_images) {
315+
if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '2x.jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2)) {
316+
$this->errors[] = sprintf(
317+
'Original image is corrupt %s for product ID %s or bad permission on folder.',
318+
$existing_img,
319+
(int) $imageObj->id_product
320+
);
321+
}
322+
}
323+
} catch (\Exception $e) {
324+
$this->errors[] = sprintf(
325+
'Unable to resize image %s for product ID %s. error: %s',
326+
$existing_img,
327+
(int) $imageObj->id_product,
328+
$e->getMessage()
329+
);
321330
}
322331
}
323332
}

0 commit comments

Comments
 (0)