better handling of preview generation errors

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2017-05-01 14:03:00 +02:00
parent 18b5e2fced
commit 4dfd90abc4
No known key found for this signature in database
GPG Key ID: CBCA68FBAEBF98C9
2 changed files with 9 additions and 4 deletions

View File

@ -303,6 +303,10 @@ class Generator {
private function generatePreview(ISimpleFolder $previewFolder, ISimpleFile $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight) { private function generatePreview(ISimpleFolder $previewFolder, ISimpleFile $maxPreview, $width, $height, $crop, $maxWidth, $maxHeight) {
$preview = $this->helper->getImage($maxPreview); $preview = $this->helper->getImage($maxPreview);
if (!$preview->valid()) {
throw new \InvalidArgumentException('Failed to generate preview, failed to load image');
}
if ($crop) { if ($crop) {
if ($height !== $preview->height() && $width !== $preview->width()) { if ($height !== $preview->height() && $width !== $preview->width()) {
//Resize //Resize
@ -325,6 +329,7 @@ class Generator {
$preview->resize(max($width, $height)); $preview->resize(max($width, $height));
} }
$path = $this->generatePath($width, $height, $crop); $path = $this->generatePath($width, $height, $crop);
try { try {
$file = $previewFolder->newFile($path); $file = $previewFolder->newFile($path);

View File

@ -563,7 +563,7 @@ class OC_Image implements \OCP\IImage {
case IMAGETYPE_JPEG: case IMAGETYPE_JPEG:
if (imagetypes() & IMG_JPG) { if (imagetypes() & IMG_JPG) {
if (getimagesize($imagePath) !== false) { if (getimagesize($imagePath) !== false) {
$this->resource = imagecreatefromjpeg($imagePath); $this->resource = @imagecreatefromjpeg($imagePath);
} else { } else {
$this->logger->debug('OC_Image->loadFromFile, JPG image not valid: ' . $imagePath, array('app' => 'core')); $this->logger->debug('OC_Image->loadFromFile, JPG image not valid: ' . $imagePath, array('app' => 'core'));
} }
@ -573,7 +573,7 @@ class OC_Image implements \OCP\IImage {
break; break;
case IMAGETYPE_PNG: case IMAGETYPE_PNG:
if (imagetypes() & IMG_PNG) { if (imagetypes() & IMG_PNG) {
$this->resource = imagecreatefrompng($imagePath); $this->resource = @imagecreatefrompng($imagePath);
// Preserve transparency // Preserve transparency
imagealphablending($this->resource, true); imagealphablending($this->resource, true);
imagesavealpha($this->resource, true); imagesavealpha($this->resource, true);
@ -583,14 +583,14 @@ class OC_Image implements \OCP\IImage {
break; break;
case IMAGETYPE_XBM: case IMAGETYPE_XBM:
if (imagetypes() & IMG_XPM) { if (imagetypes() & IMG_XPM) {
$this->resource = imagecreatefromxbm($imagePath); $this->resource = @imagecreatefromxbm($imagePath);
} else { } else {
$this->logger->debug('OC_Image->loadFromFile, XBM/XPM images not supported: ' . $imagePath, array('app' => 'core')); $this->logger->debug('OC_Image->loadFromFile, XBM/XPM images not supported: ' . $imagePath, array('app' => 'core'));
} }
break; break;
case IMAGETYPE_WBMP: case IMAGETYPE_WBMP:
if (imagetypes() & IMG_WBMP) { if (imagetypes() & IMG_WBMP) {
$this->resource = imagecreatefromwbmp($imagePath); $this->resource = @imagecreatefromwbmp($imagePath);
} else { } else {
$this->logger->debug('OC_Image->loadFromFile, WBMP images not supported: ' . $imagePath, array('app' => 'core')); $this->logger->debug('OC_Image->loadFromFile, WBMP images not supported: ' . $imagePath, array('app' => 'core'));
} }