Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding useful feedback to Gd2.php exceptions #1339

Merged
merged 1 commit into from
Dec 30, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions lib/Varien/Image/Adapter/Gd2.php
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,10 @@ private function _getCallback($callbackType, $fileType = null, $unsupportedText
$fileType = $this->_fileType;
}
if (empty(self::$_callbacks[$fileType])) {
throw new Exception($unsupportedText);
throw new Exception("{$unsupportedText}. Type was: {$fileType}. File was: {$this->_fileName}");
}
if (empty(self::$_callbacks[$fileType][$callbackType])) {
throw new Exception('Callback not found.');
throw new Exception("Callback not found. Callbacktype was: {$callbackType}. File was: {$this->_fileName}");
}
return self::$_callbacks[$fileType][$callbackType];
}
Expand All @@ -257,17 +257,17 @@ private function _fillBackgroundColor(&$imageResourceTo)
if ($isAlpha) {

if (!imagealphablending($imageResourceTo, false)) {
throw new Exception('Failed to set alpha blending for PNG image.');
throw new Exception('Failed to set alpha blending for PNG image. File was: {$this->_fileName}');
}
$transparentAlphaColor = imagecolorallocatealpha($imageResourceTo, 0, 0, 0, 127);
if (false === $transparentAlphaColor) {
throw new Exception('Failed to allocate alpha transparency for PNG image.');
throw new Exception('Failed to allocate alpha transparency for PNG image. File was: {$this->_fileName}');
}
if (!imagefill($imageResourceTo, 0, 0, $transparentAlphaColor)) {
throw new Exception('Failed to fill PNG image with alpha transparency.');
throw new Exception('Failed to fill PNG image with alpha transparency. File was: {$this->_fileName}');
}
if (!imagesavealpha($imageResourceTo, true)) {
throw new Exception('Failed to save alpha transparency into PNG image.');
throw new Exception('Failed to save alpha transparency into PNG image. File was: {$this->_fileName}');
}

return $transparentAlphaColor;
Expand Down Expand Up @@ -296,7 +296,7 @@ private function _fillBackgroundColor(&$imageResourceTo)
list($r, $g, $b) = $this->_backgroundColor;
$color = imagecolorallocate($imageResourceTo, $r, $g, $b);
if (!imagefill($imageResourceTo, 0, 0, $color)) {
throw new Exception("Failed to fill image background with color {$r} {$g} {$b}.");
throw new Exception("Failed to fill image background with color {$r} {$g} {$b}. File was: {$this->_fileName}");
}

return $color;
Expand Down Expand Up @@ -347,7 +347,7 @@ private function _getTransparency($imageResource, $fileType, &$isAlpha = false,
public function resize($frameWidth = null, $frameHeight = null)
{
if (empty($frameWidth) && empty($frameHeight)) {
throw new Exception('Invalid image dimensions.');
throw new Exception('Invalid image dimensions. File was: {$this->_fileName}');
}

// calculate lacking dimension
Expand Down