Fix Fatal error on invalid image

If user has uploaded an invalid image the original code would crash when called from template
This commit is contained in:
Marijn Kampf 2015-11-20 08:06:50 +00:00 committed by marijnkampf
parent ba6078ee5b
commit 006717a3cc

View File

@ -870,11 +870,13 @@ class UploadField extends FileField {
$width = $this->getPreviewMaxWidth();
$height = $this->getPreviewMaxHeight();
if ($file->hasMethod('getThumbnail')) {
return $file->getThumbnail($width, $height)->getURL();
$r = $file->getThumbnail($width, $height);
if ($r) return $r->getURL();
} elseif ($file->hasMethod('getThumbnailURL')) {
return $file->getThumbnailURL($width, $height);
} elseif ($file->hasMethod('Fit')) {
return $file->Fit($width, $height)->getURL();
$r = $file->Fit($width, $height);
if ($r) return $r->getURL();
} else {
return $file->Icon();
}