Skip to content

Commit

Permalink
Catch exception on product image generation to avoid process stopping…
Browse files Browse the repository at this point in the history
… on resize error
  • Loading branch information
jf-viguier committed Nov 25, 2024
1 parent 5da0635 commit 66c22d7
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions src/Commands/Image/ImageGenerateAbstract.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,22 +302,31 @@ protected function regenerateNewImages(string $dir, array $type, bool $productsI
if (file_exists($existing_img) && filesize($existing_img)) {
foreach ($type as $imageType) {
if (!file_exists($dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg')) {
if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg', (int) $imageType['width'], (int) $imageType['height'])) {
$this->errors[] = sprintf(
'Original image is corrupt %s for product ID %s or bad permission on folder.',
$existing_img,
(int) $imageObj->id_product
);
}

if ($generate_hight_dpi_images) {
if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '2x.jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2)) {
try {
if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '.jpg', (int) $imageType['width'], (int) $imageType['height'])) {
$this->errors[] = sprintf(
'Original image is corrupt %s for product ID %s or bad permission on folder.',
$existing_img,
(int) $imageObj->id_product
);
}

if ($generate_hight_dpi_images) {
if (!ImageManager::resize($existing_img, $dir . $imageObj->getExistingImgPath() . '-' . stripslashes($imageType['name']) . '2x.jpg', (int) $imageType['width'] * 2, (int) $imageType['height'] * 2)) {
$this->errors[] = sprintf(
'Original image is corrupt %s for product ID %s or bad permission on folder.',
$existing_img,
(int) $imageObj->id_product
);
}
}
} catch (\Exception $e) {
$this->errors[] = sprintf(
'Unable to resize image %s for product ID %s. error: %s',
$existing_img,
(int) $imageObj->id_product,
$e->getMessage()
);
}
}
}
Expand Down

0 comments on commit 66c22d7

Please sign in to comment.