Thumbnail class: minor refactor of generate method
This commit is contained in:
parent
e3b67c4022
commit
9010123d18
@ -255,14 +255,18 @@ class Thumbnail
|
||||
'_' . $this->width . 'x' . $this->height . $this->filename_suffix . '.' . $ext;
|
||||
|
||||
// Ensure the thumbnail subdirectory exists.
|
||||
if (!is_dir(THUMBSDIR . '/' . $this->image->getSubdir()))
|
||||
mkdir(THUMBSDIR . '/' . $this->image->getSubdir(), 0755, true);
|
||||
$target_dir = THUMBSDIR . '/' . $this->image->getSubdir();
|
||||
if (!is_dir($target_dir))
|
||||
mkdir($target_dir, 0755, true);
|
||||
|
||||
if (!is_writable($target_dir))
|
||||
throw new Exception('Thumbnail directory is not writable!');
|
||||
|
||||
// No need to preserve every detail.
|
||||
$thumb->setImageCompressionQuality(80);
|
||||
|
||||
// Save it in a public spot.
|
||||
$thumb->writeImage(THUMBSDIR . '/' . $this->image->getSubdir() . '/' . $thumb_filename);
|
||||
$thumb->writeImage($target_dir . '/' . $thumb_filename);
|
||||
|
||||
// Let's remember this for future reference...
|
||||
$this->markAsGenerated($thumb_filename);
|
||||
@ -273,7 +277,6 @@ class Thumbnail
|
||||
// Finally, return the URL for the generated thumbnail image.
|
||||
return THUMBSURL . '/' . $this->image->getSubdir() . '/' . $thumb_filename;
|
||||
}
|
||||
// Blast! Curse your sudden but inevitable betrayal!
|
||||
catch (ImagickException $e)
|
||||
{
|
||||
throw new Exception('ImageMagick error occurred while generating thumbnail. Output: ' . $e->getMessage());
|
||||
@ -331,12 +334,11 @@ class Thumbnail
|
||||
if ($success)
|
||||
{
|
||||
$thumb_selector = $this->width . 'x' . $this->height . $this->filename_suffix;
|
||||
$this->thumbnails[$thumb_selector] = $filename !== 'NULL' ? $filename : '';
|
||||
$this->thumbnails[$thumb_selector] = $filename !== 'NULL' ? $filename : null;
|
||||
return $success;
|
||||
}
|
||||
else
|
||||
throw new UnexpectedValueException('Thumbnail queuing query failed');
|
||||
|
||||
return $success;
|
||||
}
|
||||
|
||||
private function markAsQueued()
|
||||
|
Loading…
Reference in New Issue
Block a user